0

Is there an example or documentation on handling the posted "_search" and "filters" data and using it to query the database for result?

Thanks...

fletchsod
  • 3,560
  • 7
  • 39
  • 65

1 Answers1

0

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • We don't want to use "loadonce: true" anymore. We're found it to cause more problems than it is worth (when we kept adding, hacking or customizing JQuery scripts). We decided to let the back-end webserver do the heavy works instead. The disadvantage with Javascript is it's a runtime environment, so we're out of luck on lack of reliable Javascript compiler. We noticed Tony is not very active on maintaining or merging people's patches to jqGrid GitHub source code. So we decided we're better off let the back-end webserver do the work & less headache for us. We can't wait forever. :-( – fletchsod Aug 02 '13 at 13:57
  • Okay, we'll figure it out on writing sql server scripts on our own. Thanks for trying. – fletchsod Aug 02 '13 at 13:58