PDA

View Full Version : DwrGridFilters



otatop
23 Oct 2008, 12:21 PM
This is an extension of the ext grid filters from the ext example but modified to work with dwr. It's been overridden to concatenate the filter params and always return the results in a single "filter" parameter.

This is designed to work with the dwr proxy from http://extjs.com/forum/showthread.php?t=19529. Make sure you're using the baseparams with your dwr proxy instead of using the loadArgsKey.


Ext.namespace("Ext.ux.grid");

Ext.ux.grid.DwrGridFilters = Ext.extend(Ext.grid.GridFilters, {
filtersText: commonLocale.filters,

// modified to concatinate all the filter options as a single string
buildQuery: function(filters) {
var filterDataString = "";
for(var i=0, len=filters.length; i<len; i++) {
var f = filters[i];

filterDataString += f.field + "<F#>";
for(var key in f.data) {
filterDataString += key + "<=>" + f.data[key] + "<;>";
}
filterDataString += "<D#>";
}

return {filter: filterDataString};
},
// modified so it always returns filters whether they are active or not
getFilterData: function() {
var filters = [];

this.filters.each(function(f) {
var d = [].concat(f.serialize());
if (d.length == 0) {
filters.push({field: f.dataIndex, data: null});
}
else {
for(var i=0, len=d.length; i<len; i++) {
filters.push({field: f.dataIndex, data: d[i]});
}
}
});

return filters;
}
})