Dynamically setting jqGrid search

You are using the jqGrid search option but in one instance you want to enable the search but on another you want to disable the search for the same grid.



The problem: This cannot be done, in short, by setting the properties dynamically, like so:

gridComplete: function() {

setGridParam({

            gridModel: true,
            gridNames: false,
            gridToolbar: true,
            autosearch: false,
            enableClear: true,
            enableSearch: true,
            toolbar: [true, "top"]

});

}

Setting the search option dynamically during a loadComplete, or gridComplete, or any other event, also does not work dynamically:

 

setColProp('MyProperty', {search: false});

or

setColProp('MyProperty', {search: true});

The solution: So in order to do this you will need to write some custom jQuery to hide/remove this on the fly. So go ahead and set the search params as if you will be performing the search always:

gridComplete: function() {

setGridParam({

            gridModel: true,
            gridNames: false,
            gridToolbar: true,
            autosearch: false,
            enableClear: true,
            enableSearch: true,
            toolbar: [true, "top"]

});

}

Also make sure that the search property is set to true for the search column in the colModel.

Now all you need to do is remove the grid search table and all the search buttons from the footer:

//Remove the grid search table
$('form.filterform').remove();

//Remove the buttons
$(item + 'Pager').find('.navtable.nav-table-left .nav-row td:nth-child(9)').nextAll().remove();

Of course you may wan to hide them using jQuery's hide() function in stead if you want to show/hide them on the fly, but remember that you are working with tables here so you need to avoid using jQuery show() function as it sets the DISPLAY css property to BLOCK in stead of a HTML table's cell (referring to the "td").

Print | posted @ Wednesday, July 8, 2009 7:45 AM

Comments on this entry:

Gravatar # re: Dynamically setting jqGrid search
by web tasarim at 6/27/2011 5:00 PM

I really liked these trends as a web designer. shares are beautiful. We expect shares More
Post A Comment
Title:
Name:
Email:
Comment:
Verification: