Does anyone know how to "capture" the values in the autofilters?
I have a grid where the user double-click on a row, and loads a page with data related to the row he/she clicked. When the user returns to the grid I would like to reload the grid with the same autofilters he/she had before double-clicking.
I would prefer NOT to load the new page in a separate tab or window or popup but rather capture and save the autofilters and then use those values to reload the grid.
I haven't tried it yet, but the documentation has a small script under Search Onload which should do the trick for restoring the values :
// initialize search, 'name' field equal to (eq) 'Client 1'
$sarr = <<< SEARCH_JSON
{
"groupOp":"AND",
"rules":[
{"field":"name","op":"eq","data":"Maria Anders"}
]
}
SEARCH_JSON;
Thanks in advance for any help.
Just in case anybody is listening, I figured out a way to do it.
in jqgrid_dist.php, there is a section that deals with the search conditions, starting around line: 1058.
You can save the exact search string that is used to a session variable, like this:
$_SESSION["jqgrid_searchstr"] = $searchstr;
After that, you can re-use the value of that session variable when loading the grid again:
// initialize search
$sarr = $_SESSION["jqgrid_searchstr"];
$grid["search"] = true;
$grid["postData"] = array("filters" => $sarr );
The only "trouble" with this is that the values the user inputs into the actual fields on the search bar are not displayed, they are simply used to filter.
Anyone know how to alter the displayed values in those fields?
Hello Andres,
This would set default value in filter toolbar.
$col["searchoptions"] = array("defaultValue"=>'Ana');
$cols[] = $col;
You can check the session search array and update the column's search value.
I used the following to occupy the filter fields :
$jsonobj = json_decode( $_SESSION["jqgrid_searchstr"] );
$filters = $jsonobj->rules;
foreach($filters as $filter) {
switch ($filter->field){
case p_sku:
$f_p_sku = $filter->data;
break;
….
}
}
And then in the col[] part (after $col = array();)
if ($f_p_sku <> NULL){
$col["searchoptions"] = array("defaultValue"=>$f_p_sku);
}
After that i could refresh all i wanted without losing the filters.
One note, when wanting to clear the filters, you need to empty the $_SESSION["jqgrid_searchstr"] var
I did this with an extra button