JqGrid 分组不起作用
JqGrid grouping not working
我尝试使用 jQgrid 对我的记录进行分组,但它无法正常工作,您可以从下面的链接中看到
如上图所示,记录没有正确分组。
我使用的代码如下:
$(document).ready(function () {
$('#ProductProductInventoryGrid').jqGrid({
colNames: ["Id","Date","Category","Code", "Name","Total Quantity","Total Weigth","Unit","UsedW","UsedQ"],
colModel: [
{ name: 'CatId', index: 'CatId', width: 5, sortable: true, align: "left", formatter: 'string',hidden: false },
{ name: 'InventoryDate', index: 'InventoryDate', width: 50, align: "left", sortable: true, search: false },
{ name: 'CategoryName', index: 'CategoryName', width: 150, sortable: false, align: "left", search: false, searchoptions: { sopt: ['cn', 'ne', 'eq'] }, formatter: 'string' },
{ name: 'ProductCode', index: 'ProductCode', width: 180, sortable: true, align: "left", search: false, formatter: 'string' },
{ name: 'ProductName', index: 'ProductName', width: 120, sortable: true, align: "left", search: true, searchoptions: { sopt: ['cn', 'ne', 'eq'] }, formatter: 'String' },
{ name: 'TotalQuantity', index: 'TotalQuantity', width: 60, sortable: true, align: "center", search: false, sorttype: 'number', formatter: 'number', summaryType: 'sum' },
{ name: 'TotalWeight', index: 'TotalWeight', width: 80, sortable: true, align: "right", search: false, sorttype: 'number', formatter: 'number', summaryType: 'sum' },
{ name: 'UnitMeasureCode', index: 'UnitMeasureCode', width: 60, sortable: true, align: "right", search: false, formatter: 'string' },
{ name: 'UsedWeight', index: 'UsedWeight', width: 60, sortable: true, align: "right", search: false, sorttype: 'number', formatter: 'number', summaryType: 'sum' },
{ name: 'UsedQuantity', index: 'UsedQuantity', width: 60, sortable: true, align: "center", search: false, sorttype: 'number', formatter: 'number', summaryType: 'sum' }
],
grouping: true,
groupingView : {
groupField: ['CatId'],
groupColumnShow : [false],
groupText : ['<b>{0}</b>'],
groupCollapse : false,
groupOrder: ['asc'],
groupSummary : [true],
showSummaryOnHide: true,
groupDataSorted : true
},
footerrow: true,
userDataOnFooter: true,
url: ServerBaseURL + "dashboard/getProductInventory",
mtype: 'GET',
cache: false,
datatype: 'json',
caption: "",
sortname: 'ProductName',
sortorder: "asc",
emptyrecords: '@Resources.lblNoData',
autowidth: false,
width: 1100,
shrinkToFit: true,
autoheight: true,
height: 'auto',
rownumbers: false,
altRows: true,
altclass: 'myAltRowClass',
multiselect: false,
viewrecords: true,
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
userdata: "userdata"
}
});
谢谢帮助
问候
更多信息:
我已尝试按照评论中的建议使用 fiddle,但无法获取网格显示数据。不是 si 起诉 fiddle 所以不知道哪里出了问题。
下面是我的 return 示例数据:
var serverResponse = {
"rows":[
{ "CatId" :"3", "InventoryDate":"24/11/2015 15:08:00", "CategoryName":"MECHES", "ProductCode":"50F207229#434299004", "ProductName":"MECHE LENTE", "TotalQuantity":" 8", "TotalWeight":"0,0000", "UnitMeasureCode":"Pcs", "UsedQuantity":"4", "UsedWeight ":"0,0000", "Weight":"0,00", "RemainingQuantity":"0", "RemainingWeight":"0,0000" },
{ "CatId":"1", "InventoryDate":"24/11/2015 12:12:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170400596", "ProductName": "EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"25,00", "RemainingQuantity":"16", "RemainingWeight":"25,0000" },
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170500598", "ProductName":"EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"25,00", "RemainingQuantity":"16", "RemainingWeight:""25,0000" },
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170500599", "ProductName":"EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg ", "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"25,00", "RemainingQuantity":"16", "RemainingWeight":"25,0000" },
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170500600", "ProductName":"EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"5", "UsedWeight":"7,8125", "Weight":"25,00", "RemainingQuantity":"6", "RemainingWeight":"17,1875" },
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170600601", "ProductName:":"EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"0", "UsedWeight":"0,0000","Weight":"25,00", "RemainingQuantity":"16", "RemainingWeight":"25,0000" },
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170600602", "ProductName":"EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"25,00", "RemainingQuantity":"16", "RemainingWeight":"25,0000"},
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170700603", "ProductName":"EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"25,00", "RemainingQuantity":" 16", "RemainingWeight":"25,0000" },
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170700604", "ProductName":"EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"0", "UsedWeight":"0,0000","Weight":"25,00", "RemainingQuantity":"16", "RemainingWeight":"25,0000" },
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170700605", "ProductName":"EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"25,00", "RemainingQuantity":" 16", "RemainingWeight":"25,0000" },
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170800606", "ProductName":"EURONIX", "TotalQuantity ":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"25,00", "RemainingQuantity":"16", "RemainingWeight":"25,0000" },
{ "CatId":"2", "InventoryDate":"24/11/2015 13:18:00", "CategoryName":"DETONATEURS", "ProductCode":"12640#143290051681", "ProductName":"PYRO ERIKA", "TotalQuantity":"100", "TotalWeight":"0,0000", "UnitMeasureCode":"Pcs", "UsedQuantity":"90", "UsedWeight":"0,0000", "Weight":"0,00", "RemainingQuantity":"80", "RemainingWeight":"0,0000 "},
{ "CatId":"3", "InventoryDate":"24/11/2015 15:12:00", "CategoryName":"MECHES", "ProductCode":"50F207229#434299005", "ProductName":"MECHE LENTE", "TotalQuantity":" 8", "TotalWeight":"0,0000", "UnitMeasureCode":"Pcs", "UsedQuantity":"3", "UsedWeight":"0,0000", "Weight":"0,00", "RemainingQuantity":"2", "RemainingWeight":" 0,0000" },
{ "CatId":"3", "InventoryDate":"24/11/2015 15:14:00", "CategoryName:":"MECHES", "ProductCode":"50F207229#434299006", "ProductName":"MECHE LENTE", "TotalQuantity":" 8", "TotalWeight":"0,0000", "UnitMeasureCode":"Pcs", "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"0,00", "RemainingQuantity":"8", "RemainingWeight":" 0,0000"},
{ "CatId":"3", "InventoryDate":"24/11/2015 15:15:00", "CategoryName":"MECHES", "ProductCode":"50F207229#434299007", "ProductName":"MECHE LENTE", "TotalQuantity":" 8", "TotalWeight":"0,0000", "UnitMeasureCode":"Pcs", "UsedQuantity":"2", "UsedWeight":"0,0000", "Weight":"0,00", "RemainingQuantity":"4", "RemainingWeight":" 0,0000" },
{ "CatId":"2", "InventoryDate":"27/11/2015 19:40:00", "CategoryName":"DETONATEURS", "ProductCode":"UN0360#H34122", "ProductName":"LIGNE DE TIR NONEL", "TotalQuantity":" 120", "TotalWeight":"0,0000", "UnitMeasureCode":"Pcs", "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"0,00", "RemainingQuantity":"120", "RemainingWeight":"0,0000" }
]
};
$("#jqGrid").jqGrid({
url: "/echo/json/", // use JSFiddle echo service
postData: {
json: JSON.stringify(serverResponse) // needed for JSFiddle echo service
},
mtype: "POST", // needed for JSFiddle echo service
datatype: "json",
colModel: [
{ label: 'CatId', name: 'CatId', key: true, width: 10 },
{ label: 'InventoryDate', name: 'InventoryDate', width: 70 },
{ label: 'ProductName', name: 'ProductName', width: 150 },
{ label: 'RemainingQuantity', name: 'RemainingQuantity', width: 150 }
],
loadonce:true,
viewrecords: true,
rowList: [20,30,50],
width: 780,
height: 250,
rowNum: 20,
sortname: 'ProductName',
grouping: true,
groupingView: {
groupField: ["CatId"],
groupColumnShow: [true],
groupText: [
"CatId: <b>{0}</b>"
],
groupOrder: ["asc"],
groupSummary: [true],
groupSummaryPos: ['header'],
groupCollapse: false
}
});
由于语法错误,您的演示无法运行。
的用法
"RemainingWeight:""25,0000"
需要固定为
"RemainingWeight":"25,0000"
此外,您需要删除 rows
不需要的包装。固定码是https://jsfiddle.net/OlegKi/zqLp4yrg/
可以看到服务器 returns 未排序的数据 ,但数据需要按 groupField
排序(["CatId"]
在你的例子中).
您可以通过使用 datatype: "local"
解决问题,例如:https://jsfiddle.net/OlegKi/zqLp4yrg/1/ 或从服务器返回正确排序的数据。
我尝试使用 jQgrid 对我的记录进行分组,但它无法正常工作,您可以从下面的链接中看到
如上图所示,记录没有正确分组。 我使用的代码如下:
$(document).ready(function () {
$('#ProductProductInventoryGrid').jqGrid({
colNames: ["Id","Date","Category","Code", "Name","Total Quantity","Total Weigth","Unit","UsedW","UsedQ"],
colModel: [
{ name: 'CatId', index: 'CatId', width: 5, sortable: true, align: "left", formatter: 'string',hidden: false },
{ name: 'InventoryDate', index: 'InventoryDate', width: 50, align: "left", sortable: true, search: false },
{ name: 'CategoryName', index: 'CategoryName', width: 150, sortable: false, align: "left", search: false, searchoptions: { sopt: ['cn', 'ne', 'eq'] }, formatter: 'string' },
{ name: 'ProductCode', index: 'ProductCode', width: 180, sortable: true, align: "left", search: false, formatter: 'string' },
{ name: 'ProductName', index: 'ProductName', width: 120, sortable: true, align: "left", search: true, searchoptions: { sopt: ['cn', 'ne', 'eq'] }, formatter: 'String' },
{ name: 'TotalQuantity', index: 'TotalQuantity', width: 60, sortable: true, align: "center", search: false, sorttype: 'number', formatter: 'number', summaryType: 'sum' },
{ name: 'TotalWeight', index: 'TotalWeight', width: 80, sortable: true, align: "right", search: false, sorttype: 'number', formatter: 'number', summaryType: 'sum' },
{ name: 'UnitMeasureCode', index: 'UnitMeasureCode', width: 60, sortable: true, align: "right", search: false, formatter: 'string' },
{ name: 'UsedWeight', index: 'UsedWeight', width: 60, sortable: true, align: "right", search: false, sorttype: 'number', formatter: 'number', summaryType: 'sum' },
{ name: 'UsedQuantity', index: 'UsedQuantity', width: 60, sortable: true, align: "center", search: false, sorttype: 'number', formatter: 'number', summaryType: 'sum' }
],
grouping: true,
groupingView : {
groupField: ['CatId'],
groupColumnShow : [false],
groupText : ['<b>{0}</b>'],
groupCollapse : false,
groupOrder: ['asc'],
groupSummary : [true],
showSummaryOnHide: true,
groupDataSorted : true
},
footerrow: true,
userDataOnFooter: true,
url: ServerBaseURL + "dashboard/getProductInventory",
mtype: 'GET',
cache: false,
datatype: 'json',
caption: "",
sortname: 'ProductName',
sortorder: "asc",
emptyrecords: '@Resources.lblNoData',
autowidth: false,
width: 1100,
shrinkToFit: true,
autoheight: true,
height: 'auto',
rownumbers: false,
altRows: true,
altclass: 'myAltRowClass',
multiselect: false,
viewrecords: true,
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
userdata: "userdata"
}
});
谢谢帮助 问候
更多信息:
我已尝试按照评论中的建议使用 fiddle,但无法获取网格显示数据。不是 si 起诉 fiddle 所以不知道哪里出了问题。 下面是我的 return 示例数据:
var serverResponse = {
"rows":[
{ "CatId" :"3", "InventoryDate":"24/11/2015 15:08:00", "CategoryName":"MECHES", "ProductCode":"50F207229#434299004", "ProductName":"MECHE LENTE", "TotalQuantity":" 8", "TotalWeight":"0,0000", "UnitMeasureCode":"Pcs", "UsedQuantity":"4", "UsedWeight ":"0,0000", "Weight":"0,00", "RemainingQuantity":"0", "RemainingWeight":"0,0000" },
{ "CatId":"1", "InventoryDate":"24/11/2015 12:12:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170400596", "ProductName": "EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"25,00", "RemainingQuantity":"16", "RemainingWeight":"25,0000" },
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170500598", "ProductName":"EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"25,00", "RemainingQuantity":"16", "RemainingWeight:""25,0000" },
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170500599", "ProductName":"EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg ", "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"25,00", "RemainingQuantity":"16", "RemainingWeight":"25,0000" },
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170500600", "ProductName":"EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"5", "UsedWeight":"7,8125", "Weight":"25,00", "RemainingQuantity":"6", "RemainingWeight":"17,1875" },
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170600601", "ProductName:":"EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"0", "UsedWeight":"0,0000","Weight":"25,00", "RemainingQuantity":"16", "RemainingWeight":"25,0000" },
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170600602", "ProductName":"EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"25,00", "RemainingQuantity":"16", "RemainingWeight":"25,0000"},
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170700603", "ProductName":"EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"25,00", "RemainingQuantity":" 16", "RemainingWeight":"25,0000" },
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170700604", "ProductName":"EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"0", "UsedWeight":"0,0000","Weight":"25,00", "RemainingQuantity":"16", "RemainingWeight":"25,0000" },
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170700605", "ProductName":"EURONIX", "TotalQuantity":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"25,00", "RemainingQuantity":" 16", "RemainingWeight":"25,0000" },
{ "CatId":"1", "InventoryDate":"24/11/2015 11:09:00", "CategoryName":"EXPLOSIFS", "ProductCode":"50F300440#151026E3170800606", "ProductName":"EURONIX", "TotalQuantity ":"16", "TotalWeight":"25,0000", "UnitMeasureCode":"Kg" , "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"25,00", "RemainingQuantity":"16", "RemainingWeight":"25,0000" },
{ "CatId":"2", "InventoryDate":"24/11/2015 13:18:00", "CategoryName":"DETONATEURS", "ProductCode":"12640#143290051681", "ProductName":"PYRO ERIKA", "TotalQuantity":"100", "TotalWeight":"0,0000", "UnitMeasureCode":"Pcs", "UsedQuantity":"90", "UsedWeight":"0,0000", "Weight":"0,00", "RemainingQuantity":"80", "RemainingWeight":"0,0000 "},
{ "CatId":"3", "InventoryDate":"24/11/2015 15:12:00", "CategoryName":"MECHES", "ProductCode":"50F207229#434299005", "ProductName":"MECHE LENTE", "TotalQuantity":" 8", "TotalWeight":"0,0000", "UnitMeasureCode":"Pcs", "UsedQuantity":"3", "UsedWeight":"0,0000", "Weight":"0,00", "RemainingQuantity":"2", "RemainingWeight":" 0,0000" },
{ "CatId":"3", "InventoryDate":"24/11/2015 15:14:00", "CategoryName:":"MECHES", "ProductCode":"50F207229#434299006", "ProductName":"MECHE LENTE", "TotalQuantity":" 8", "TotalWeight":"0,0000", "UnitMeasureCode":"Pcs", "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"0,00", "RemainingQuantity":"8", "RemainingWeight":" 0,0000"},
{ "CatId":"3", "InventoryDate":"24/11/2015 15:15:00", "CategoryName":"MECHES", "ProductCode":"50F207229#434299007", "ProductName":"MECHE LENTE", "TotalQuantity":" 8", "TotalWeight":"0,0000", "UnitMeasureCode":"Pcs", "UsedQuantity":"2", "UsedWeight":"0,0000", "Weight":"0,00", "RemainingQuantity":"4", "RemainingWeight":" 0,0000" },
{ "CatId":"2", "InventoryDate":"27/11/2015 19:40:00", "CategoryName":"DETONATEURS", "ProductCode":"UN0360#H34122", "ProductName":"LIGNE DE TIR NONEL", "TotalQuantity":" 120", "TotalWeight":"0,0000", "UnitMeasureCode":"Pcs", "UsedQuantity":"0", "UsedWeight":"0,0000", "Weight":"0,00", "RemainingQuantity":"120", "RemainingWeight":"0,0000" }
]
};
$("#jqGrid").jqGrid({
url: "/echo/json/", // use JSFiddle echo service
postData: {
json: JSON.stringify(serverResponse) // needed for JSFiddle echo service
},
mtype: "POST", // needed for JSFiddle echo service
datatype: "json",
colModel: [
{ label: 'CatId', name: 'CatId', key: true, width: 10 },
{ label: 'InventoryDate', name: 'InventoryDate', width: 70 },
{ label: 'ProductName', name: 'ProductName', width: 150 },
{ label: 'RemainingQuantity', name: 'RemainingQuantity', width: 150 }
],
loadonce:true,
viewrecords: true,
rowList: [20,30,50],
width: 780,
height: 250,
rowNum: 20,
sortname: 'ProductName',
grouping: true,
groupingView: {
groupField: ["CatId"],
groupColumnShow: [true],
groupText: [
"CatId: <b>{0}</b>"
],
groupOrder: ["asc"],
groupSummary: [true],
groupSummaryPos: ['header'],
groupCollapse: false
}
});
由于语法错误,您的演示无法运行。
的用法"RemainingWeight:""25,0000"
需要固定为
"RemainingWeight":"25,0000"
此外,您需要删除 rows
不需要的包装。固定码是https://jsfiddle.net/OlegKi/zqLp4yrg/
可以看到服务器 returns 未排序的数据 ,但数据需要按 groupField
排序(["CatId"]
在你的例子中).
您可以通过使用 datatype: "local"
解决问题,例如:https://jsfiddle.net/OlegKi/zqLp4yrg/1/ 或从服务器返回正确排序的数据。