0

I am using jqGrid and I am required to save its specific state if user has performed some search and the grid shows the records as per search criteria. When user performs search and clicks on edit button to edit the record, I am required to show the grid in last left status of the records shown as per search criteria. Just went around several answers of Oleg, but still unable to get my thing working. My jqGrid code is as under:

$('#grid').jqGrid({
url: GetPath,
datatype: 'json',
mtype: 'POST',
search: true,
postdata: {filters: postfilt, sord: postsord, sidx: postsort },
colNames: // ColumnNamesArray
colModel: //The ColumnModel.
page: postpage,
pager: jQuery('#pager'),
rowNum: 10,
rowList: [10, 20, 30, 40],
viewrecords: true,
sortname: 'DefaultSortColName',
sortorder: 'DESC',
loadonce: true,
gridview: true,
ignoreCase: true,
jsonReader: {
root: 'rows',
page: 'page',
total: 'total',
records: 'records',
repeatitems: false,
userdata: 'userdata',
Id: 'PrimaryKeyId'
},
autowidth: true,
multiselect: false
)};

I am having one common js file inside which the jqGrids code exists. Every time I need to populate a jqGrid, I simply need to call the js file before which I need to set few javascript variables say for example: for specifying url of jqgrid, etc. Notice the variable names postfilt, postsord and postsort. I am simply assigning values to these variables as per my requirement: when my grid is loading for the first time, the filters are blank so as to load the grid with all of the data, and assigning these variables with postdata filter values which I have saved earlier when some filter is being applied by user. The issue I am facing is, my this dynamic filter kind of functionality works fine for the first grid on which I implemented it. But it doesn't works for my other grids on which I am trying to implement it.(Of course the different grid search filters are saved for different grids). I have checked while debugging in Chrome's F12 that my filter variables does shows the proper values which are to be provided for a jqGrids postData filter, but still it loads the jqGrid with all of the data every time and not with the filter when required. I tried several times for calling a function in gridComplete or loadComplete for providing postdata filters after getting loaded with my grid, but still being unsuccessfull on filling my jqGrid with last provided search criteria on its first load. Where am I being wrong in providing the criterias for jqgrid so as to load it in its last left state when it is loaded for the first time ? Any help is appreciated.

Edit: One of my saved postdata search filter for jqGrid is as under:

{"groupOp":"AND","rules":[{"field":"ClientName","op":"cn","data":"client"}]}
  • Is there any way around through which we can perform some cache clearing for jqGrid. Simply cache clearing and filter clearing is being different thing. Is there any way around for clearing some cache associated or loading a fresh new jqGrid ? – Vinit Sharma Apr 17 '15 at 07:23
  • Experts, please tell me if something is not getting cleared with my question. I have tried explaining my question to the best. If something is not clear, please let me know. – Vinit Sharma Apr 20 '15 at 06:16
  • If you write comment to you own question, then only the persons, who wrote already his comments here, will get notifications. Your previous comments didn't generate any notifications to somebody. What you can do is to *write comment to some other answer*. It will inform the author of the answer and all people who wrote his comments to the answer. – Oleg Apr 21 '15 at 07:55

1 Answers1

1

The main reason of your problem is the wrong parameter which you use. JavaScript is case sensitive. There are no postdata parameter. So it will be just ignored by jqGrid. There are exist postData parameter instead. So to include the filter and to set the initial sorting in the request to url: GetPath you need do the following:

$('#grid').jqGrid({
    ...
    search: true,
    postData: {filters: postfilt },
    sortname: postsort,
    sortorder: postsord,
    ...
});

In the same way Id property of jsonReader will be ignored. You should use id instead. Moreover jqGrid merge default properties of jsonReader (see the documentation) with the values included in the grid options. So you don't need to include the default properties like root: 'rows', page: 'page' and other. jsonReader should looks like

jsonReader: {
    repeatitems: false,
    id: 'PrimaryKeyId'
}
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Yes, changing the parameters as per what you said did helped me solving for my problem. Now I am able to apply a preload filter. Many thanks for helping me out @Oleg. – Vinit Sharma Apr 21 '15 at 09:21
  • @VinitSharma: You are welcome! I'm glad that I could help you. – Oleg Apr 21 '15 at 09:24