3

While I've been able to add my own post data programmatically, I cannot seem to figure out how to get this code to send _search: true in the request.

var data = grid.jqGrid("getGridParam", "postData");
data._search = true;
data.searchString = id.toString();
data.searchOper = "eq";
data.searchField = "userid";
grid.jqGrid("setGridParam", { "postData": data });
grid.trigger("reloadGrid");

The fields are added correctly, but somewhere along the way _search appears to be set to false, because every request has it set to false. Is there some other thing I have to do to have it "true"? I'm running a toolbar search, but most of the time when this code will be called there's nothing entered, and a decent chunk of utility code on my server checks _search before handling searches.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Groxx
  • 2,399
  • 1
  • 23
  • 32

1 Answers1

6

There is an additional parameter, search, which need be set to initiate the searching. The _search parameter of postData need not be set explicitly. I recommend to look up some old answers where you find examples how to work with searching:

Community
  • 1
  • 1
Oleg
  • 217,934
  • 30
  • 386
  • 757
  • Adding `data.search=true` just adds `{search:true}` to my postData, `{_search:false}` is still there. I also tried adding `data.filters=""`, which behaves similarly. I don't see any other suggestions in those 3 or other questions for jqGrid searching I've seen :\ – Groxx Dec 30 '10 at 22:16
  • 3
    @Groxx: I wrote that is the jqGrid parameter. You should use `grid.jqGrid('setGridParam', { search: true, postData: newPostData });` to set it and **NOT** as `data.search=true` which add additional `postData` option. Please Look one more my first link http://stackoverflow.com/questions/4492963/jqgrid-client-side-searching/4509018#4509018. – Oleg Dec 30 '10 at 22:27
  • @Groxx: if you try the demo http://www.ok-soft-gmbh.com/jqGrid/CheckboxesWithVerticalHeaders1.htm (from the next link http://stackoverflow.com/questions/3974324/jqgrid-using-multiple-methods-to-filter-data/3979490#3979490) you can click on the check box outside of grid and see how the corresponding search will started and the grid are filtered. – Oleg Dec 30 '10 at 22:30
  • aaah, I missed that distinction. Thanks very much, it's working now! – Groxx Dec 30 '10 at 22:40
  • @Groxx: You welcome! Existance of both `search` and `_search` seems me personally also a little confused. Nevertheless it is so and to be able to force searching in jqGrid one have to use `search` and not `_search`. – Oleg Dec 30 '10 at 22:46