I\'m trying to get a JqGrid to do some client-side filtering (and sorting) just after it has finished loading in the data. I can set the search-field correctly, but calling
You use datatype: 'json'
in combination with loadonce: true
. So you should call mygrid[0].triggerToolbar()
inside of the loadComplete
event handle. Only after the data are loaded you should filter the data. Probably you should place the code with triggerToolbar
inside of setTimeout
method to start the filtering already after the datatype
will be changed to 'local'
during loadonce: true
. So the code of your loadComplete
event handle could be about the following:
loadComplete: function () {
var gridDOM = this; // save $("#list")[0] in a variable
if ($(this).jqGrid('getGridParam', 'datatype') === 'json') {
// the first load from the server
setTimeout(function () {
$("#gs_PID").val('AA');
gridDOM.triggerToolbar();
}, 100);
}
}
Additionally I don't full understand how you use the code fragment which you posted and why you need to use gridUnload
method.
UPDATED: Free jqGrid fork of jqGrid supports forceClientSorting: true
option, which force sorting and optional filtering of the data, returned from the server, before displaying the first page of data. It makes unneeded the above code. Instead of that one can set postData.filters
use
forceClientSorting: true,
search: true,
postData: {
filters: {
groupOp: "AND",
rules: [
{ op: "le", field: "PID", data: "AA" }
]
}
}
see the demo.