1

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 there another, better way?

Thanks!

Donald T
  • 10,234
  • 17
  • 63
  • 91

3 Answers3

2

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}]);
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Unfortunately, there are a lot of fields on my form, and jqGrid's way of serializing it would be virtually impossible (I wish I could just pass form.serialize(), but that is not supported). – Donald T Jul 28 '11 at 20:03
  • @Jack B.: with respect of `postData: { yourParam: function() { return form.serialize();} }` you can do send serialized form values always together with other grid parameters. You should just exactly describe your situation and decide which data and when you want be sent to the server. See [here](http://stackoverflow.com/questions/2928371/how-to-filter-the-jqgrid-data-not-using-the-built-in-search-filter-box/2928819#2928819) for details. – Oleg Jul 28 '11 at 21:05
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

Community
  • 1
  • 1
Samson
  • 2,801
  • 7
  • 37
  • 55
1

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.

Nahuen
  • 71
  • 5