Searching on a Single Field

Calling Convention:
jQuery("#grid_id").searchGrid( properties );

Where:


Properties

Property Description Default
checkInput when set to true prerforms input validation according to the rules in editrules option in colModel false
Clear the text of the button when you click to clear search string "Reset"
closeAfterSearch closes the dialog after we click on the search button (and perform the search). true
dirty applicable only in navigator false
drag sets the dialog to dragable true
Find the text of the button clicked to start the Find "Find"
height the height of Search dialog 200
left the initial left position of search dialog 0
modal sets dialog in modal mode false
top the initial top position of search dialog 0
width the width of search dialog 300


Events

Event Parameters Description
onInitializeSearch form_id fires once when creating the data for searching.
beforeShowSearch form_id fires before showing the form
afterShowSearch form_id fires after showing the form

Notes

If the top and left off-set properties are not set, the dialog appears at the upper left corner of the grid. Top and left off-sets are in relation to the viewing window, not the grid, so {top:10, left:10} will be indented slightly from the window, and may be nowhere near the grid.


To exclude a field from the search possibilities, set the search option in colModel to false. Example:

colModel[{name:'somename'…, search:false}…]


When the find button is clicked, jqGrid adds three parameters to the url, in name=value pairs:


Translation string for the search options:

odata : ['equal', 'not equal', 'less', 'less or equal','greater','greater or equal', 'begins with','ends with','contains' ],

If you want to change or remove the order change it in sopt:

sopt: null // ['bw','eq','ne','lt','le','gt','ge','ew','cn']

by default all options are allowed. The codes are as follows:

eq - equal ( = )
ne - not equal ( <> )
lt - less than ( < )
le - less than or equal to ( <= )
gt - greater than ( > )
ge - greater than or equal to ( >= )

bw - begins with ( LIKE val% )
ew - ends with (LIKE %val )
cn - contain (LIKE %val% )

Typically this method is applied to the click action of a button or link. For example,

jQuery("#bsdata").click(function(){ jQuery("#search").searchGrid( {sopt:['cn','bw','eq','ne','lt','gt','ew']} ); });


We can set common options for all search dialogs using the $.jgrid.search object with $extend()

The default values are:

$.jgrid.search = { caption: "Search...", Find: "Find", Reset: "Reset", odata : ['equal', 'not equal', 'less', 'less or equal','greater','greater or equal', 'begins with','ends with','contains' ] };

$.extend($.jgrid.search,{Find:'Search'})
will replace the text of search button from Find to Search.


  Last Updated: 3/1/2009 | © Tony's jqGrid - a jQuery Plugin, 2010