views:

246

answers:

3

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

A: 

You can try to use dataInit property of searchoptions in the colModel. This function has one parameter elem. The $(elem) will represent the input html element which you can initialize with any data which you need.

UPDATED: Try to include following option in colModel in the description of the column where you want 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 "Test" text as the filter and simulate press enter key. I suppose that searchOnEnter set to default value true. The forwarding of the filter string (like "Test") is very depended on the structure of your program, but I hope that it can be easy implemented.

UPDATED 2: Probably there are different understanding how should be understand "a page with a jqgrid on it with filter row at the top". I read it like a setting of filter in the filter toolbar, because the filter toolbar will be added as a row on the top of grids rows. My sollution live can be seen here http://www.ok-soft-gmbh.com/jqGrid/CustomFilter.htm.

Oleg
A: 

You can modify the url that jqGrid calls, and add the filter option to the querystring, then handle it on the server side.

$(link).click(function(){

$(".mygrid").jqGrid('setGridParam',{url:"server.php?useMyFilter=1"})
});
CPettit
This is almost right. After you do this, you need to `$("#grid").trigger("reloadGrid");`
Craig Stuntz
+2  A: 
Neo
oh the first solution is awesome I didn't know I was doing it on the serverside like your second solution but I just tried this and it works!
jsd911
I am not sure that one asked for such kind of filter. There are filter in the fillter toolbar (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:toolbar_searching). If one do want to set some kind of filters which exist outside of jqGrid it seems to me better to do this with respect of `postData` (see http://stackoverflow.com/questions/2928371/how-to-filter-the-jqgrid-data-not-using-the-built-in-search-filter-box/2928819#2928819). This works not only with HTTP GET but with HTTP POST also. Morevere if you build filter url manually it should be `'myfilter='+encodeURIComponent(columnname)`
Oleg