加載本地數據,請求的數據類型是:local緩存
$grid.jqGrid({ datatype: "local", height:500, autowidth: 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,即後臺返回的須要展現的數據,存到變量裏面,進行下面方法處理,直接就將數據插入到表格裏面了,速度快。spa
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'); } }