How to get jqGrid current search criteria?

15,296

Solution 1

Just to close this question I did this this the following line:

grid.getGridParam("postData").filters;

With this I get the filter expression the jqGrid generates when we're applying filters on its data.

Solution 2

$('#myGrid').getGridParam("postData").filters;

will give you a string (i don't know why string. why not JSON)

"{"groupOp":"AND","rules":[{"field":"Name","op":"bw","data":"a"}]}" 

rules have the search criteria. If i have multiple search criteria, all would be there

"{"groupOp":"AND","rules":[{"field":"Name","op":"bw","data":"a"},{"field":"Description","op":"bw","data":"d"}]}" 

Solution 3

var search = grid.getGridParam("postData").search;

...works for me.

Share:
15,296
AlexCode
Author by

AlexCode

Senior Consultant dealing with computers professionally since 2000. Experienced developer, architect and team leader feeling at ease around anything form the front-end to infrastructure. You can subscribe to my blog at: http://www.instanceofanobject.com

Updated on July 16, 2022

Comments

  • AlexCode
    AlexCode almost 2 years

    I need to get the exact same thing the jqGrid passes on the GET/POST _search parameter.

    How can I do this?

  • AlexCode
    AlexCode almost 13 years
    Thanks! My question body isn't quite correct, what I want isn't the _search which is a boolean but the filters that actually contains the json representation of the current filter applyed on the grid. So the way of getting is: grid.getGridParam("postData").filters;
  • Kevin Gauthier
    Kevin Gauthier almost 13 years
    I don't understand what it is that you're asking for.
  • bkwdesign
    bkwdesign over 9 years
    The new API mode will look like this: $('#myGrid').jqGrid('getGridParam', "postData").filters
  • low_rents
    low_rents about 8 years
    I also don't understand why it returns a string and not JSON.
  • Sergiy Ostrovsky
    Sergiy Ostrovsky over 6 years
    This doesn't work for me when using datatype: "json".