分组不在jqGrid中正确显示数据

时间:2015-02-16 11:47:19

标签: javascript jquery jqgrid

我正在尝试使用jqGrid在组中显示数据。为了减少进入,它工作正常。但随着行的增加。它为同一个名称创建了多个组。

这是我的jqGrid片段。



var v = xmlString.XmlToString();
	$("#Addresses").jqGrid({
		datatype: 'xmlstring',
		datastr: v,
		mtype: 'GET',
		
		beforeRequest: function () {
			//alert('beforeRequest');
		},
		loadError: function (xhr, status, error) {
			$(this).HideBusy();
			//   alert(status);
			//     alert(error);
			alert(xhr.responseText);
		},

		loadComplete: function (data) {
			//            var top_rowid = $('#Addresses tr:nth-child(2)').attr('id');
			//            $("#Addresses").setSelection(top_rowid, true);
			$(this).HideBusy();
		},
		ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
		xmlReader: { repeatitems: false, root: "BPAddresses", row: 'row' },
		colNames: ['Address', 'AdresType'],
		colModel: [
					{ name: 'AddressName', index: 'AddressName', sortable: false },
					{ name: 'AddressType', index: 'AddressType', sortable: false, align: "left", formatter: FormatBPAddress, unformat: UnFormatBPAddress }
			   ],
		viewrecords: true,
		gridview: true,
		autowidth: true,
		shrinkToFit: false,
		height: 150,
		width: 110,
		rowNum: 100,
		beforeSelectRow: function (id, e) {
			//set contact person values back to xml
			var Name = $("#Addresses").jqGrid('getCell', id, 'AddressName');
			selectedContactID = Name;
			var addType = $("#Addresses").jqGrid('getCell', id, 'AddressType');
			selectedAddType = addType;
			//debugger;
			$("#gbox_Addresses").block({ message: null });
			return true;
		},
		onSelectRow: function (id) {
			var Address = $("#Addresses").jqGrid('getCell', id, 'AddressName');
			SelectedAddresses.find("BPAddresses>row").each(function (index) {
				if ($(this).find('AddressName').text() == Address) {
					var v1 = $(this).XmlToString();
					var v2 = '<BPAddresses>' + v1 + '</BPAddresses>';
					var $parsedXML = $($.parseXML(v2));
					$(this).SetValuesToControl("BusinessPartner #uxAddresses", $parsedXML, dataMember);
					$("#uxUpdateAdd").removeAttr("disabled");
					$("#uxCancelAdd").removeAttr("disabled");
				}
			});
		},
		grouping: true,
		groupingView: {
			groupField: ['AddressType'],
			groupColumnShow: [false],
			groupCollapse: true,
			plusicon: 'ui-icon-triangle-1-e',
			minusicon: 'ui-icon-triangle-1-s',
			openicon: 'ui-icon-arrowreturn-1-e'
		},
		scrollOffset: 0
	}).jqGrid('navGrid', '', { edit: false, add: false, del: false, searchOnEnter: false, search: false }, {}, {}, {}, { multipleSearch: false });
	

//this is my xml code.
<BPAddresses>
			<row>
				<AddressName>a1</AddressName>
				<Street>a1</Street>
				<Country>IN</Country>
				<AddressType>bo_BillTo</AddressType>
				<StreetNo>a1</StreetNo>
				<BPCode>A2</BPCode>
				<RowNum>0</RowNum>
			</row>
			<row>
				<AddressName>a2</AddressName>
				<Street>a2</Street>
				<Country>IN</Country>
				<AddressType>bo_BillTo</AddressType>
				<StreetNo>a2</StreetNo>
				<BPCode>A2</BPCode>
				<RowNum>1</RowNum>
			</row>
			<row>
				<AddressName>a3</AddressName>
				<Street>a3</Street>
				<Country>IN</Country>
				<AddressType>bo_BillTo</AddressType>
				<StreetNo>a3</StreetNo>
				<BPCode>A2</BPCode>
				<RowNum>2</RowNum>
			</row>
			<row>
				<AddressName>sh1</AddressName>
				<Country>IN</Country>
				<AddressType>bo_ShipTo</AddressType>
				<BPCode>A2</BPCode>
				<RowNum>3</RowNum>
			</row>
			<row>
				<AddressName>sh2</AddressName>
				<Country>IN</Country>
				<AddressType>bo_ShipTo</AddressType>
				<BPCode>A2</BPCode>
				<RowNum>4</RowNum>
			</row>
			<row>
				<AddressName>Define New</AddressName>
				<Street/>
				<Block/>
				<ZipCode/>
				<City/>
				<County/>
				<Country/>
				<State/>
				<BuildingFloorRoom/>
				<AddressType>bo_ShipTo</AddressType>
				<StreetNo/>
				<BPCode/>
				<RowNum/>
				<GlobalLocationNumber/>
			</row>
			<row>
				<AddressName>Define New</AddressName>
				<Street/>
				<Block/>
				<ZipCode/>
				<City/>
				<County/>
				<Country/>
				<State/>
				<BuildingFloorRoom/>
				<AddressType>bo_BillTo</AddressType>
				<StreetNo/>
				<BPCode/>
				<RowNum/>
				<GlobalLocationNumber/>
			</row>
		</BPAddresses>
&#13;
&#13;
&#13;

在上面的xml中,只有两个组,即:Bill To&amp;运送到。 它在我的网格Bill To,Ship To&amp; amp;还有一个Bill To。

有人可以帮助我吗?

PFA: enter image description here

1 个答案:

答案 0 :(得分:0)

如果您使用groupField: ['AddressType'],则输入数据必须按AddressType排序。