我有这个jqGrid:
$("#report").jqGrid( {
url: '/py/db?coll=report',
datatype: 'json',
height: 250,
colNames: ['ACN', 'Status', 'Amount'],
colModel: [ {name:'acn', sortable:true},
{name:'meta.status', sortable:true},
{name:'amount'} ],
caption: 'Show Report',
rownumbers: true,
gridview: true,
rowNum: 10,
rowList: [10,20,30],
pager: '#report_pager',
viewrecords: true,
sortname: 'acn',
sortorder: "desc",
altRows: true,
loadonce: true,
mtype: "GET",
rowTotal: 1000,
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
id: "acn"
}
});
请注意,'meta.status'列是JSON点表示法,因此从服务器发送的数据是这样的:
{"page": "1", "total": "1", "records": "5", "rows": [
{"acn":1,"meta": {"status":"Confirmed"}, "amount": 50},
{"acn":2,"meta": {"status":"Started"}, "amount": 51},
{"acn":3,"meta": {"status":"Stopped"}, "amount": 52},
{"acn":4,"meta": {"status":"Working"}, "amount": 53},
{"acn":5,"meta": {"status":"Started"}, "amount": 54} ] }
问题有两个:
答案 0 :(得分:3)
将最后一列的定义从{name:amount}
更改为{name:'amount'}
后,我可以重现您的问题:“状态”的排序不起作用,但我看不到任何错误消息(请参阅{ {3}})。
可以解决从
更改第二列定义的问题{name:'meta.status', sortable:true}
到
{name:'status', sortable:true, jsonmap: "meta.status"}
请参阅固定演示the demo。
答案 1 :(得分:1)
作为避免此问题的经验法则:
确保您的name
和index
值相同
name: 'Date', index: 'Date',
name: 'Clicks', index: 'Clicks',
...
确保设置类似
的内容$("#jqGrid").setGridParam({datatype: 'local'});
当您重新加载网格时 - 如果您正在使用它,则在重新加载时将其更正为“JSON” - 即
$("#yourGridID").setGridParam({datatype: 'json'}).trigger("reloadGrid");
最后,请确保使用
name: 'Date', index: 'Date', sortable:true
你需要它的地方。