You can implement search on a jqGrid by using the built-in search functionality provided by jqGrid. This allows you to search for specific data within the grid based on certain criteria.
Here's an example of how to implement search on a jqGrid:
javascript$("#grid").jqGrid({
// other jqGrid options
search: true,
postData: {
filters: ''
},
onSearch: function() {
var postData = $(this).jqGrid('getGridParam', 'postData');
postData.filters = JSON.stringify($(this).jqGrid('getGridParam', 'postData'));
}
});
In this example, we're setting the search
option to true
to enable search functionality. We're also setting the postData
option to an object that includes a filters
property, which will be used to store the search criteria.
The onSearch
event is triggered when the search button is clicked, and we're using this event to update the filters
property with the search criteria. We're doing this by using the JSON.stringify
method to convert the search criteria to a JSON string, which we then assign to the filters
property of the postData
object.
You can customize the search criteria by using the search options provided by jqGrid. These options allow you to specify the search field, the search operator, and the search value. Here's an example:
javascript$("#grid").jqGrid('filterToolbar', {
// search options
stringResult: true,
searchOnEnter: false,
defaultSearch: 'cn'
});
In this example, we're using the filterToolbar
method to display the search toolbar. We're also setting the stringResult
option to true
to return the search criteria as a string, the searchOnEnter
option to false
to trigger search on button click, and the defaultSearch
option to 'cn'
to search for a substring within a cell.
Once the search toolbar is displayed, the user can enter search criteria and click the search button to filter the grid data based on those criteria. The search criteria will be sent to the server as part of the postData
object, which you can use to filter the data on the server-side as well.
Comments
Post a Comment