Is there an example or documentation on handling the posted "_search" and "filters" data and using it to query the database for result?
Thanks...
Is there an example or documentation on handling the posted "_search" and "filters" data and using it to query the database for result?
Thanks...
The value _search
is just boolean. If _search
is true
then one should filter the data using filters
parameter which format described in the documentation.
One can use prmNames
option to rename _search
. For example prmNames: { search: null, nd: null }
remove unneeded parameters _search
and nd
and another example prmNames: { search: "isSearching" }
rename default _search
parameter to isSearching
.
The handling of the posted filters
parameter depends on many implementation details which you use. You used both jqgrid-asp.net and jqgrid-php tags of commercial products developed based on free open source jqGrid. I can't help you at all in the case because I don't know the products. Additionally I find very strange that you included PHP and ASP.NET as tags. The implementation can be completely different in both cases. Event if ASP.NET is your main platform then the database access which you use is the most important aspect of the implementation. Three typical options: Entity Framework, LINQ to SQL and SQLCommand
with SqlDataReader
need absolutely different implementation of dynamic filtering.
The answer provide an implementation example in case of usage Entity Framework. The most advantage of usage Entity Framework is the possibility to use ObjectQuery.Where with string parameter. In the way one can construct string with parameters from filters
which should be used in WHERE
part of SQL statement. You can use mostly the same approach to build SQLCommand
command with parameters.
LINQ to SQL on the other side don't have the possibility and one have to use more sophisticated approach like here or to use some libraries (like this one).
What I would really recommend you is to consider to use loadonce: true
. If the dataset which you need display in the grid contains some hundred (or even a thousand) of rows then it could be more effective to return all the data to jqGrid (the data should be just correctly sorted) and use loadonce: true
to implement local filtering and paging of data. It can simplify your server code and the grid could be even more responsible from the users point of view because JavaScript engine is now quickly enough and local filtering by jqGrid could be more quickly as sending request to the server and usage of server side filtering.