gpt4 book ai didi

javascript - jqGrid 排序或搜索不适用于具有 json 点表示法的列

转载 作者:行者123 更新时间:2023-11-30 10:52:09 25 4
gpt4 key购买 nike

我有这个 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 是 true 还是 false。
  • 如果我尝试搜索(在将 loadonce 设置为 true 之后)列 meta.status(其他不带点符号的列也可以),那么它会抛出这样的 javascript 错误。 alt text

最佳答案

在将最后一列的定义从 {name:amount} 更改为 {name:'amount'} 后,我可以重现您的问题:' 上的排序Status' 不起作用,但我看不到任何错误消息(请参阅 the demo )。

可以通过更改第二列的定义来解决问题

{name:'meta.status', sortable:true}

{name:'status', sortable:true, jsonmap: "meta.status"}

查看固定演示 here .

关于javascript - jqGrid 排序或搜索不适用于具有 json 点表示法的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4639476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com