gpt4 book ai didi

javascript - JQGrid 不改变页面

转载 作者:行者123 更新时间:2023-11-28 09:37:11 26 4
gpt4 key购买 nike

我的 jqgrid 表有问题:我加载了 json,我有我的表,但我只能看到表的最后一页,无法更改页面。

js代码:

$("#list").jqGrid(
{
url:'test.json',
datatype: "json",
mtype: 'GET',
colNames:['id','model','cc','nation','prod'],
colModel:[
{name:'id', index:'id', jsonmap:"id", width:25},
{name:'model', index:'model', jsonmap:"model", width:50},
{name:'cc', index:'cc', jsonmap:"cc", width:25},
{name:'nation', index:'nation', jsonmap:"nation", width:50},
{name:'prod', index:'prod', jsonmap:"prod", width:50}
],
rowNum: "2",
page: "1",
rowList: [2,4,6],
autowidth: true,
pager: '#pager',
height: "100%",
sortname: 'id',
caption: "Elenco delle Moto",
jsonReader: {root: 'rows',page: 'page',total: 'total',records: 'records',repeatitems: false,id: 'id'},

loadComplete: function() {
grid.setGridHeight('auto');
}
});
$("#list").jqGrid('navGrid','#pager',{edit:false,add:false,del:false,search:false});
$("#visual").hide();

和我的 json 文件:

{
"total": "3",
"page": "1",
"records": "5",
"rows":
[
{
"Id": "1",
"model": "shiver",
"cc": "750",
"nation": "italy",
"prod": "aprilia"
},
{
"Id": "2",
"model": "monster",
"cc": "696",
"nation": "italy",
"prod": "ducati"
}
],
"page":"2",
"rows":
[
{
"Id": "3",
"model": "z750",
"cc": "750",
"nation": "japan",
"prod": "kawasaki"
},
{
"Id": "4",
"model": "hornet",
"cc": "700",
"nation": "japan",
"prod": "honda"
}
],
"page":"3",
"rows":
[
{
"Id": "5",
"model": "speedtriple",
"cc": "1000",
"nation": "england",
"prod": "buell"
}
]

}

我尝试了很多次,但总是相同的结果..有人可以帮助我吗?

最佳答案

您的响应一次应仅包含一个页面(使用正确的 page 值来说明这是哪个页面),因此第一页的 JSON 应如下所示:

{
"total": "3",
"page": "1",
"records": "5",
"rows": [
{ "Id": "1", "model": "shiver", "cc": "750", "nation": "italy", "prod": "aprilia" },
{ "Id": "2", "model": "monster", "cc": "696", "nation": "italy", "prod": "ducati" }
]
}

jqGrid 将进一步请求下一页,您应该检查请求的 pagerows 参数。第一个将告诉您应该发回哪个页面,第二个将告诉您当前页面大小是多少(这很重要,因为您已经使用了 rowList 选项,因此可以更改页面大小)。

关于javascript - JQGrid 不改变页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12854837/

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