Is there a way to programmatically set a filter in jquery jqgrid?

I have a page with jqgrid on it with a filter line at the top. I want to have a link on another page that loads this grid page, but with a filter set to one of the columns. Is it possible to do this from a link or any other workaround that people can offer?

+8
jquery asp.net-mvc jqgrid
source share
4 answers

the way I decided is to pass the following code:

var myfilter = { groupOp: "AND", rules: [] }; myfilter.rules.push({ field: "DataIssuesYN", op: "eq", data: "Y" }); 

and then in jqGrid setup, I go to postData:

  postData: (myfilter) ? { filters: JSON.stringify(myfilter)} : {}, 
+4
source share

You can try using the dataInit property of searchoptions in colModel . This function has one parameter elem . $(elem) will represent an input html element that you can initialize with whatever data you need.

UPDATED . Try to include the following command in colModel in the description of the column in which you want to set the filter:

 searchoptions:{ dataInit:function(elem){ $(elem).val("Test"); setTimeout(function(){ $(elem).focus().trigger({ type: 'keypress', charCode: 13 }); },500); } } 

in this example, I set the text "Test" as a filter and simulate an input key press. I assume that searchOnEnter set to the default value true . Forwarding a filter string (for example, "Test") is very dependent on the structure of your program, but I hope it can be easily implemented.

UPDATED 2 . Perhaps there is a different understanding of how to understand "a page with jqgrid on it with a filter line at the top." I read it as a filter setting in the filter toolbar, because the filter toolbar will be added as a line at the top of the grid lines. My live solution can be seen here Filter settings in the filter toolbar

0
source share

You can change the URL that jqGrid calls and add a filter parameter to the query string and then process it on the server side.

 $(link).click(function(){ $(".mygrid").jqGrid('setGridParam',{url:"server.php?useMyFilter=1"}) }); 
0
source share

Solution 1

prgramatic in javascript: use hideCol and give it a column name or a set of columns [colnames, otherone], the jqGrid object given by one name will hide this column with this name. Given the array colnames ["name1", "name2"], it will hide the columns with these names, 'name1' and 'name2', in the example. Names in colname or colnames must be valid names from colModel. Remember that this will not change the width of the column, so you still have to change the colModel example:

colModel :[{name:'photo', index:'photo', width:605, sortable:false} ,... ]

 <script> jQuery("#grid_id").setGridParam({...}).hideCol("photo").trigger("reloadGrid"); </script> 

solution 2: solution 1:

 jQuery(document).ready(function(){ jQuery("#list").jqGrid({ url:'json.php?myfilter=columnname', datatype: 'json',//or xml? mtype: 'GET', //<!--important colNames:['Banner','name', 'city','state','Zip Code','Country'], colModel :[ {name:'photo', index:'photo', width:605, sortable:false} , 

then in json.php you can extract the column key from the array before printing it

0
source share

All Articles