Jqgrid和渐进增强:成功从HTML,本地JSON,到远程JSON,但寻呼机无法正常启动?

看看我的小提琴中发生了什么: http : //jsfiddle.net/tbH5H/

我正在尝试使用jgrid实现正确的渐进增强。 一切都很好,除了我不知道如何在第一次加载时给jqgrid正确的寻呼机信息。 我的服务器端脚本为SEO机器人转储JSON和相应的HTML表。 但是,如何在第一次本地加载时为jqgrid提供正确的总页数呢? 正如您在小提琴中看到的那样,在远程数据拉取后,寻呼机可以正常工作。

HTML

IDState
1Alaska

JS

 $("#grid").jqGrid({ datatype:'local', // Server side script dumps this JSON out for first load only, // other requests will come from remote source, see further down... data: [{"id":1,"state":"Alabama"}, {"id":2,"state":"Alaska"}, {"id":3,"state":"Arizona"}, {"id":4,"state":"Arkansas"}, {"id":5,"state":"California"}, {"id":6,"state":"Colorado"}, {"id":7,"state":"Connecticut"}, {"id":8,"state":"Delaware"}, {"id":9,"state":"Florida"}, {"id":10,"state":"Georgia"}], height: 250, width: 450, rowNum:10, colNames:['ID','State'], colModel:[ {name:'id', index:'id', width:50}, {name:'state', index:'state', width:100} ], caption: "States of the USA", pager: '#pager' }); $("#grid").jqGrid('navGrid', '#pager',{edit: false, add: false, del: false, search: false, refresh: true}); // Convert the grid to read remotely, but don't trigger a unnecessary reload... // (because queries are expensive! We shouldn't need to run them twice!) $('#grid').jqGrid("setGridParam",{datatype:"json", mtype:"POST", url:"/some/url/here"}); $('#grid').jqGrid("setGridParam",{postData:data}); 

得到它了!

我需要使用localReader 。 看到新的小提琴: http : //jsfiddle.net/2UCk6/

 localReader: { // These values would be inserted on first page load from server-side script page: function(obj) { return 1; }, total: function(obj) { return 5; }, records: function(obj) { return 50; } }, 

您的数据应采用以下格式:

 { "total": "xxx", "page": "yyy", "records": "zzz", "rows" : [{"id":1,"state":"Alabama"}, {"id":2,"state":"Alaska"}, {"id":3,"state":"Arizona"}, {"id":4,"state":"Arkansas"}, {"id":5,"state":"California"}, {"id":6,"state":"Colorado"}, {"id":7,"state":"Connecticut"}, {"id":8,"state":"Delaware"}, {"id":9,"state":"Florida"}, {"id":10,"state":"Georgia"}] } 

哪里:

 total = total pages for the query page = current page of the query records = total number of records for the query rows = an array that contains the actual data 

您需要为上面的某些内容配置json reader ,如下所示:

  jsonReader : { root: "rows", page: "page", total: "total", records: "records", repeatitems: false, cell: "cell", ... }, ... 

更多信息可以在这里找到示例 – http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data

更新

当数据类型是本地时,您不能拥有该function。 当数据类型是本地时,Jqgird会忽略页面/记录等。 您应该尝试虚拟滚动 – >转到Jqgrid演示 – > 3.7中的新function – >虚拟滚动。

或者您可能应该进行服务器调用并返回您打算用作本地页面/记录等的数据?