PDA

View Full Version : parameter field or property in remote filter with grid and store



badenski
4 Sep 2012, 1:41 AM
Hi,

to avoid managing two param's name in remote script,
is it possible to give the same param field name to both filters with ExtJS ?

store filter (Ext.util.Filter)
param property is used to identify field name

{property: "fieldname",value:"myvalue"}

grid filter (Ext.ux.grid.FiltersFeature)
param field is used to identify field name

{field:"fieldname", value:"astring", type:"string"}

vietits
4 Sep 2012, 2:43 AM
Try this:


var store = Ext.create('Ext.data.Store', {
...
remoteFilter: true,
filters: [{
property: 'field1', value: 'value1'
},{
property: 'field2', value: 'value2'
}],
proxy: {
type: 'ajax',
...
encodeFilters: function(filters) {
var min = [],
length = filters.length,
i = 0;


for (; i < length; i++) {
min[i] = {
field: filters[i].property,
value: filters[i].value
};
}
return this.applyEncoding(min);
}
}
});

badenski
4 Sep 2012, 4:10 AM
I test it and it works quite well !
Thanks for your answer ! :)

I've found an alternative solution (comments on FiltersFeature helps me). I override function buildQuery and change key name field by property :


tmp.push(Ext.apply(
{},
{property: f.field},
f.data
));

GGG65
14 Jan 2013, 12:01 AM
vietits, your solution solved my problem where my remote filters were not working at all... no idea why, but with your change it finally started working (though in my case it was added to data.Model, not data.Store).

No idea how it works exactly (or why it doesn't work otherwise), but this was a life-saver. (FiltersFeature didn't work for some reason for me due to a conflict with some form features).

Thanks!