【发布时间】:2011-01-09 13:48:22
【问题描述】:
我有这个 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} ] }
问题有两个方面:
- 排序不适用于带有点符号的列,此处为“meta.status”。它甚至不会在列标题上显示可排序的图标,即使单击标题也不会发生任何事情。排序不起作用,无论 loadonce 是真还是假。
- 如果我尝试搜索(在将 loadonce 设置为 true 之后)列 meta.status(其他没有点表示法的列也可以),那么它会抛出这样的 javascript 错误。
【问题讨论】:
-
你试过不带引号的
meta.status吗? -
如果你想让我在 colModel 中给出 meta.status 而没有 qutoes,它不会起作用,因为 Javascript 会抛出 meta.status 未定义的错误。
标签: javascript json syntax jqgrid