PDA

View Full Version : Ext.Direct and GridFilters plugin



twaindev
15 Sep 2009, 10:49 AM
Hi All,

Is it possible to use the GridFilters plugin with an Ext.Direct data store?

The filters don't seem to be included in the call.

Thanks
André

twaindev
15 Sep 2009, 1:44 PM
I tried using ParamsAsHash: true as this should send all arguments, but this results in a stack overflow. Anyone else experiencing this?

Thanks,
André

ishobr
22 Oct 2009, 7:11 PM
GridFilters using DirectStore work for me. This is code snippet from the DirectStore:



var store = new Ext.data.DirectStore({
api: {
read: CustomerAction.get,
create: CustomerAction.insert,
update: CustomerAction.update,
destroy: CustomerAction.del
}
,baseParams: {filter: ""}
,paramOrder: ["start", "limit", "sort", "dir", "filter"]
,root: 'data'
,fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string', allowBlank: false},
'vip_no', 'phone', 'mobile', 'fax', 'email', 'address', 'city'
]
,remoteSort: true
,sortInfo: {
field: 'name'
,direction: 'ASC'
}
,writer: new Ext.data.JsonWriter()
});


We must add 'filter' as baseParams and add 'filter' to paramOrder. Don't forget to set encode: true on filter definition.

Ihsan

jenner
26 Oct 2009, 3:13 PM
I tried using ParamsAsHash: true as this should send all arguments, but this results in a stack overflow. Anyone else experiencing this?


Nope, no stack overflow here. Actually using gridfilters and a DirectStore with paramsAsHash: true is really simple, just override the GridFilters.buildQuery() method:


var filters = new Ext.ux.grid.GridFilters({
encode: false,
local: false,
filters: myFilters,
buildQuery: function(flts) {
var ret = {}, f;
for (var i = 0, l = flts.length; i < l; i++) {
f = flts[i];
ret[f.field] = f.data;
}
return {'filters': ret};
}
});


HTH,
jenner

pezze
26 Feb 2010, 5:27 AM
Nope, no stack overflow here. Actually using gridfilters and a DirectStore with paramsAsHash: true is really simple, just override the GridFilters.buildQuery() method:


var filters = new Ext.ux.grid.GridFilters({
encode: false,
local: false,
filters: myFilters,
buildQuery: function(flts) {
var ret = {}, f;
for (var i = 0, l = flts.length; i < l; i++) {
f = flts[i];
ret[f.field] = f.data;
}
return {'filters': ret};
}
});
HTH,
jenner

I've used an alternative solution. Here it is my my buildQuery:


var filters = new Ext.ux.grid.GridFilters({
encode: false,
local: false,
menuFilterText: 'Filtro',
filters: [{
type: 'string',
dataIndex: 'companyName',
disabled: false
}],
buildQuery: function(flts) {
if (flts.length == 0)
return {'filter': ''};
else
return {'filter': Ext.util.JSON.encode(flts)};
}

});


In this way I can deserialize Json class on server side. This solution works even if you don't use any filter the first time you load the the grid and you can use paramsAsHash: false in the store.

twaindev
3 Mar 2010, 5:38 AM
Hi all,

Finally found some time to sort this out and all your help was invaluable.

Thanks.