Custom Data Filtering with jQuery Grid plug-in

In order to customize the built-in Grid filtering, you can set the ‘filter’ member of the source object to point to a custom filtering function. The filtering function has three parameters that the Grid passes – the filters set by the user, the data to filter and the rows count. The filtering function is expected to return an array of filtered data records which will be displayed by the Grid. Here’s a sample definition of the ‘source’ object with a custom filtering function.
var source =
{
localdata: data,
datatype: "array",
filter: function (filters, data, length) {
var filtereddata = new Array();
var filterslength = filters.length;
for (row = 0; row < length; row++) {
var datarow = data[row];
var filterresult = undefined;
// loop through the filters and evaluate the value.
for (j = 0; j < filterslength; j++) {
var filter = filters[j].filter;
var value = datarow[filters[j].datafield];
var result = filter.evaluate(value);
if (filterresult == undefined) filterresult = result;
else {
if (filter.operator == 'or') {
filterresult = filterresult || result;
}
else {
filterresult = filterresult && result;
}
}
}
if (filterresult) {
filtereddata[filtereddata.length] = datarow;
}
}
return filtereddata;
}
};

About admin


This entry was posted in JavaScript, JavaScript Plugins, JavaScript UI, JavaScript UI Plugins, JavaScript UI Widgets, JavaScript Widgets, jQuery, jQuery Plugins, jQuery UI, jQuery UI Plugins, jQuery UI Widgets, jQuery Widgets, jQWidgets, jqxGrid and tagged , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.



Leave a Reply