PDA

View Full Version : [FIXED] Grid Filters Feature clear existing filters on store



navr84
9 Apr 2013, 2:26 AM
Existing Filters on store getting cleared in 4.2 when a grid filter from the filter feature menu is applied.

Consider the following store config:



var store = Ext.create('Ext.data.Store', {
model : 'Qreda.model.Test',
remoteSort : true,
buffered : true,
pageSize : 100,

filters : [{
field : 'testId',
type : 'numeric',
comparison : 'eq',
value : 2
}]
});


When the following store is used in a grid with filter feature, filtering from the menu clears the default filter on the grid.

*EDIT BY SLEMMON
User suggested override:


Ext.define("Foo.override.ux.grid.FiltersFeature", {
override: "Ext.ux.grid.FiltersFeature",




buildQuery: function (filters) {
var p = {}, i, f, root, dataPrefix, key, tmp,
len = filters.length;




if (!this.encode) {
for (i = 0; i < len; i++) {
f = filters[i];
root = [this.paramPrefix, '[', i, ']'].join('');
p[root + '[field]'] = f.field;




dataPrefix = root + '[data]';
for (key in f.data) {
p[[dataPrefix, '[', key, ']'].join('')] = f.data[key];
}
}
} else {
tmp = [];
for (i = 0; i < len; i++) {
f = filters[i];
tmp.push(Ext.apply({}, {
field: f.field
},
f.data));
}




/*
* NOTE: We have to add the existing filters on the store here manually.
*/
tmp.push.apply(tmp, Ext.decode(
this.store.getProxy().encodeFilters(this.store.filters.getRange())
));




// only build if there is active filter
if (tmp.length > 0) {
p[this.paramPrefix] = Ext.JSON.encode(tmp);
}
}
return p;
}
});

slemmon
10 Apr 2013, 3:05 PM
I'm having some trouble building a test case to reproduce the issue. Would you be able to post a more complete code snippet to demonstrate the issue you're seeing?

mono blaine
13 Apr 2013, 3:22 AM
When a store makes a request to the server with some filters defined through the Ext.ux.grid.FiltersFeature, any existing filters on the store are ignored, thus not sent with the request.

I've been using the following override for a while, but you have to mess with the implementation of Ext.data.proxy.Server.encodingFilters a little bit. Because the serialization of store filters and FiltersFeature filters are a little different.


Ext.define("Foo.override.ux.grid.FiltersFeature", {
override: "Ext.ux.grid.FiltersFeature",


buildQuery: function (filters) {
var p = {}, i, f, root, dataPrefix, key, tmp,
len = filters.length;


if (!this.encode) {
for (i = 0; i < len; i++) {
f = filters[i];
root = [this.paramPrefix, '[', i, ']'].join('');
p[root + '[field]'] = f.field;


dataPrefix = root + '[data]';
for (key in f.data) {
p[[dataPrefix, '[', key, ']'].join('')] = f.data[key];
}
}
} else {
tmp = [];
for (i = 0; i < len; i++) {
f = filters[i];
tmp.push(Ext.apply({}, {
field: f.field
},
f.data));
}


/*
* NOTE: We have to add the existing filters on the store here manually.
*/
tmp.push.apply(tmp, Ext.decode(
this.store.getProxy().encodeFilters(this.store.filters.getRange())
));


// only build if there is active filter
if (tmp.length > 0) {
p[this.paramPrefix] = Ext.JSON.encode(tmp);
}
}
return p;
}
});

slemmon
15 Apr 2013, 11:31 AM
Thanks for the report! I have opened a bug in our bug tracker.