I have been fancying the idea of creating my own search dialog to create the search criteria that differs from the approach mentioned in the jqGrid documentation. This for many reasons, including but not limited to the good support of date ranges, more user-friendly search dialogue , etc.
I just would like to know if anyone has attempted the creation of this flow and how effective it is as a workaround to create your own complex search before diving into implementing it:
- create a dialog where user insert the information required for search (different than the current one for the advanced custom search of jqGrid)
- The request sent to the server and retrieved as JSON which I can insert in the grid using
addJSONData
method.
- jqGrid will preserve the paging for the searched values such that the paging will work correctly (with the fetched data based on the search criteria) once the
next
and previous
buttons are hit.
So the question is: can I make the next
and previous
navigations work for me if I change the filters
using setGridParam
to include the same data
used in the search for the process of navigation. This could happen when the onPaging
event is triggered and with simple logic which dictates that the paging is happening for a searched data?
Thanks a lot.
First of all I can mention, that I am a little pessimistic about implementation of custom searching dialog. The reason is that you will invest much time in the implementation. I would you better recommend to use custom controls inside of standard searching dialog. After applying the changes which I suggested it is now possible.
Look at the demo which allows you to create searching dialog like
In the way you can solve many problems which you described in your question.
If you do decide to create custom searching dialog you will have to do the following:
- The new searching dialog should add information about the searching criteria in
postData
properties.
- reload the grid using
.trigger.("reloadGrid")
You don't need make separate Ajax request to the server. Reloading of the grid is what you need to do.
If you want to save the information about the filter in the postData.filters
you have to hold the standard format. In the case you can have advantage of local data filtering (datatype: 'local'
or the usage of loadonce: true
). See the demo from the answer as an example.
If you want to implement filtering of data on the server side only you can use any format of additional properties (please don't use the same name filters
). If you want to have searching filter (controls) always visible on the page I would recommend you to use the technique with postData
properties as function (see the answer).