开发者

jqGrid's "loadonce:true" and "datatype: json" don't get along

开发者 https://www.devze.com 2023-03-17 15:03 出处:网络
I have a grid in my application. To fill it with data, the user fills out a form and submits it. The server responds with JSON data containing all the results for the grid (the server is not hit again

I have a grid in my application. To fill it with data, the user fills out a form and submits it. The server responds with JSON data containing all the results for the grid (the server is not hit again).

In terms of jqGrid, the settings would be loadonce: true and datatype: "json". But these don't work together.

What I have been doing -- and it seems like a poor way of doing it -- is the following, which changes the grid settings, loads data, and changes the grid's settings back.

$("#myGrid").jqGrid("setGridParam", {datatype: "json", loadonce: true});
$("#myGrid")[0].addJSONData(data);
$("#myGrid").jqGrid("setGridParam", {datatype: "local", loadonce: true});

Is the开发者_高级运维re another, better way?

Thanks!


If you have set the correct url of the grid and the grid will be fill with the server data (with or without loadonce:true), then to reload the data from the server you can do the following:

$("#myGrid").jqGrid("setGridParam",{datatype:"json"}).trigger("reloadGrid");

or

$("#myGrid").jqGrid("setGridParam",{datatype:"json"}).trigger("reloadGrid",[{page:1}]);


I just solved the same problem using the afterSubmit event for create/edit/delete operations. Here is the question and answer:

Can't refresh jqgrid with loadonce: true


I was have the same problem, my solution was:

$("#myGrid").jqGrid('setGridParam', { url: 'MyNewUrl', datatype:"json" });
$("#myGrid").trigger("reloadGrid");

Or

$("#myGrid").jqGrid('setGridParam', { url: 'MyNewUrl', datatype:"json"}).trigger("reloadGrid");

I hope it's works for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消