0
使用情況是我想處理客戶端和服務器端的分頁排序,因爲記錄的體積可能太大我不想一次加載所有記錄。 目前ui顯示,所以下面的json包含它們以及元數據。 頁面 - 當前頁面,總計 - 總頁數和記錄 - 記錄總數。jqgrid localReader不工作
我檢查與jqgrid我不明白爲什麼這是行不通的。
當數據設置爲data:ret時,ui沒有顯示任何記錄,而在localReader中,我指定root爲數據。
當我指定數據爲data時,ui顯示記錄數據:ret.data但是尋呼機(分頁下一個prev顯示不起作用)。
的json數據是這樣的:
var ret={"data":[{"id":"1","firstName":"John","lastName":"Doe"},
{"id":"2","firstName":"John","lastName":"Burns"},
{"id":"3","firstName":"John","lastName":"Newman"},
{"id":"4","firstName":"Mike","lastName":"Vargas"},
{"id":"5","firstName":"David","lastName":"Taylor"}],
"page":1,"total":3,"records":24}
我jQuery是象下面這樣:
grid.jqGrid({
datatype: "local",
data: ret,
// root:"oldcontacts",
colNames:['ID', 'First Name','Last Name'],
colModel:[
{name:'id',index:'id', key: true, width:70, sorttype:"int"},
{name:'firstName',index:'firstName', width:90},
{name:'lastName',index:'lastName', width:100}
],
localReader : {
root :"data",
page: "page",
total: "total",
records :"records"
},
search:true,
pager:'#pager',
//jsonReader: {cell:""},
rowNum: 10,
rowList: [5, 10, 20, 50],
loadonce:false,
sortname: 'id',
sortorder: 'asc',
viewrecords: true,
sortable:false,
cmTemplate: {sortable:true},//change to false if want
multiselect:true,
multiboxonly: false,
height: "100%",
caption: "Multiple search with local data",
onSelectAll:function(aRowids,isSelected){
// this is not used in this sample.. as I removed the check all button
var i, count, id;
for (i = 0, count = aRowids.length; i < count; i++) {
id = aRowids[i];
if(isSelected)
{mysel.pushObject(id);}
else
{ mysel.removeObject(id);}
}
that.set('selection',mysel);
},
gridComplete: function(){
},
onSelectRow: function (id,isSelected,e) {
//now lets tell jqgrid not to change to yellow on simple click
Ember.$('#'+id).attr("aria-selected","false");// override default selection
Ember.$('#'+id).removeClass("ui-state-highlight");// override default selection
if (e.ctrlKey){
if (isSelected){
mysel.pushObject(id);
Ember.$('#'+id).css('background','red');
}
else
{
Ember.$('#'+id).css('background','white');
mysel.removeObject(id);
}
that.set('selection',mysel);
}
},
});
感謝您的回覆。我使用一個單獨的AJAX調用獲取數據並將其傳遞到前的jqGrid形成如上述的數據。我如何更新loadComplete上的尋呼機?我試過這個,但它沒有工作.. loadComplete:function(){ 頁面:「頁」, 總:「總」, 記錄:「記錄」, grid.updatepager(); }, – user3630294 2014-12-04 18:51:02
@ user3630294:不客氣! 「本地」':不斷變化的'page','records'和''loadComplete'和'updatepager'工程'數據類型的情況下,呼叫內lastpage'的伎倆。你需要以任何方式實現'onPaging'中的網格重新加載。所以,我認爲'數據類型的用法:「JSON」'和'loadonce:TRUE'將會使你的代碼更短。 – Oleg 2014-12-04 18:58:12