[Answer]-JqGrid toolbar search and Django

1👍

I’m not Django developer, but the server side code looks like it returns the array of all unsorted items. In the case you should use loadonce: true option of jqGrid. In the case jqGrid saves all data in internal parameters data and _index and change datatype option to "local" after the first load. After that the searching works on the client side and you don’t need to make any changes in the server code.

If you use loadonce: true option and you need reload the data from the server (for example after changing url) then you have to reset datatype to its original value datatype: "json":

$("#list_d").jqGrid("setGridParam", {
    url: "getpricelist?q=1&id=" + encodeURIComponent(ids),
    page: 1,
    datatype: "json"
}).trigger("reloadGrid");

I would recommend to consider to use additionally datatype: "local" in the second (details grid). The current code use url:'getpricelist?q=1&id=2', datatype: "json". So the second grid will be filled before a row in the first grid selected. Using datatype: "local" prevents the loading.

I recommend you to use gridview: true and autoencode: true options in the both grids and to add key: true property to the definition of "id" column in the first grid. If you do this then id of <tr> elements (the rows of the grid) will be assign to the values from id column. It can simplify editing operations.

The last remark: jqGrid assign always id attribute (known as rowid) to every row of the grids. id have to be unique over the whole page. If you have more as one grid you could have id conflicts in the grids. To be sure that you don’t have the problem you can consider to use different idPrefix parameters (for example idPrefix: "g1_" and idPrefix: "g2_") for different grids (of for one from the grids). In the case the rowid values will be build from the idPrefix and the id assigned from your data (for example id column in the first grid). If you need to cut the prefix (for example to use it as a parameter in the URL) you can use $.jgrid.stripPref method. For example you can use $.jgrid.stripPref($(this).jqGrid("getGridParam", "idPrefix"), ids) instead of id during building url of detailed grid.

👤Oleg

Leave a comment