[jqGrid]關於loadonce:true后trigger("reloadGrid")無效,loadonce:false后無法翻頁的問題(來自stackoverflow)


簡單的來說就是在setGridParam中加上參數datatype:'json',因為loadonce:true后,jqGrid只會加載一次數據,並把datatype改為local,這樣就無法完成於Server的交互通信進行數據搜索和刷新操作,因為全部數據都是提取的本地的,所以在刷新的時候重新將datatype重新定位到json,也就是指向服務器后,jqGrid就會像服務器發起請求。

例如:$("#list").setGridParam({datatype:'json', page:1}).trigger('reloadGrid');

以上方法親測可用

 

或者在jqGrid version 4.8之后,在trigger中加上參數fromServer:true,

例如:$("#list").trigger("reloadGrid", { fromServer: true, page: 1 });

此方法未測試,只是原文中提到了。

 

附送原文:

原文地址:http://stackoverflow.com/questions/5397671/jqgrid-reloadgrid-with-loadonce-set-to-true/5398136#5398136

If you use loadonce:true jqGrid change the datatype parameters to 'local' after the first load of data from the grid. All next grid reloading (sorting, paging, filtering) works local. If you want refresh the grid data from the server one more time you should set datatype to its original value ('json' or 'xml'). For example:

$("#list").setGridParam({datatype:'json', page:1}).trigger('reloadGrid');

UPDATED: Free jqGrid supports fromServer: true option of reloadGrid starting with the first release (starting with version 4.8). So one can use the code like

$("#list").trigger("reloadGrid", { fromServer: true, page: 1 });

to do the same as above. The main advantage: such code works fine with any initial value of datatype ("json", "jsonp", "xml" and so on). Free jqGrid saves original value of datatype inside of internal dataTypeOrg before changing it to "local".

One more helpful option of free jqGrid is the parameter reloadGridOptions of navGrid, which allows to specify default options of reloadGrid. Thus one can use for example

loadonce: true, navOptions: { reloadGridOptions: { fromServer: true } }

options of jqGrid, which set defaults for navGrid additionally. As the result the click on "Reload" button of navigator bar will reload the grid from the server instead of local reloading.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM