加载本地数据,请求的数据类型是:local
$grid.jqGrid({ datatype: "local", height:500, auto true, colModel: XXXXX, viewrecords: true, rowNum: 20, rowList: [20], pager: "#gridPager", rownumbers: true, shrinkToFit: false, footerrow: isfooterrow, gridComplete: function () { //表格加载完成后执行 }, onPaging: function (pageBtn) { //点击翻页按钮执行 }, onSelectRow: function (rowid) { //选中行执行 } });
通过请求获取到details,即后台返回的需要展示的数据,存到变量里面,进行下面方法处理,直接就将数据插入到表格里面了,速度快。
function loadWeightDetails(details) { debugger; if (details == null || details == "") return; var rows = details; var len = rows.length; BDList = []; $("#gridTable_PCD00003").jqGrid("clearGridData"); if (rows != null && rows != "") { //............................... ////缓存数据赋值 var localData = { page: 1, total: Math.ceil(parseInt(len) / 20), records: len, rows: rows }; var reader = { root: function (obj) { return localData.rows; }, page: function (obj) { return localData.page; }, total: function (obj) { return localData.total; }, records: function (obj) { return localData.records; }, repeatitems: false };
//通过setGridParam进行重载表格 $("#gridTable_PCD00003").setGridParam({ data: localData.rows, reader: reader }).trigger('reloadGrid'); } }