PDA

View Full Version : GridFilter: how to explicitly set the filter values



Stepan Koci
4 Jun 2011, 7:31 AM
Hi,

is it possible to set the values of some filter field using some function? I mean something like:


grid.features.filters.filter('id',300);

I would like to invoke filtering manualy without user interaction for example after page load.

Stepan Koci
9 Aug 2011, 12:22 AM
Still looking for the help.
I Can find it anywhere. Im glad for any help:-/

Nickname
9 Aug 2011, 6:04 AM
There is the filter method. You can add the filter in the afterRender event of the gridPanel or maybe in the store load event.

I use this in the grid panel


Ext.define('Webdesktop.view.administration.controllers.List', {
extend : 'Ext.grid.Panel',
//...
afterRender: function() {
var me = this;
me.callParent();
me.getStore().filter(
new Ext.util.Filter({
filterFn: function(item) {
return item.data.status == 0;
}
})
);
}
});

Stepan Koci
10 Aug 2011, 7:31 AM
Thank you!

Stepan Koci
21 Sep 2011, 6:39 AM
Hello again. Unfortunately that piece of code doesn't do exactly what I wanted it to. I would like to be able to set default filter options which then would be visible as if the user has set them himself (by clicking on the column dropdown and enabling the filters there). This solution did filter the grid data, but the UI did not show the respective filter as active. I have gone through the docs but did not find a way to achieve this.

Christiand
22 Sep 2011, 3:44 AM
this ux in version 3x had a method setFilterData() that is no longer available in it's 4.x incarnation. I'm trying to achieve the same thing as you but have failed for now.

abs
13 Oct 2011, 7:46 PM
I have to implement a basic filter via the Column header menu on my grid. I am unable to find Ext JS 4 examples for the same, any help much appreciated!!
Sencha docs seem to suggest to only use Store to filter and not grid (via the Column header menu). But I want the end user to key the filter values and not directly filter the store.

Christiand
14 Oct 2011, 2:01 AM
It's all in the example
http://docs.sencha.com/ext-js/4-0/#!/example/grid-filtering/grid-filter-local.html (http://docs.sencha.com/ext-js/4-0/#!/example/grid-filtering/grid-filter-local.html)

or a custom plugin
http://www.sencha.com/forum/showthread.php?147553-Ext.ux.grid.HeaderFIlter

mmuzamil
18 Oct 2011, 8:25 AM
I am also trying to achieve this, any update on this one?

Stepan Koci
25 Apr 2012, 5:31 AM
Anyone found the solution?
http://www.sencha.com/forum/showthread.php?135833-GridFilter-how-to-explicitly-set-the-filter-values&p=651424&viewfull=1#post651424

Christiand
25 Apr 2012, 5:37 AM
i've added to FiltersFeature.js the following:



/**
* progamatically activate a filter field with data
* @param field the field dataIndex
* @param data the data from from @link Ext.ux.grid.FiltersFeature.getFilterData
*/
setFilterData: function(field, data){
if (typeof this.view.headerCt.menu == 'undefined'){
this.forceMenuCreation();
}
var filter = this.getFilterByName(field);
var value = this.unSerialArg(data);
filter.setValue(value);
},


/**
* format a value from getFilterData to be set into field
* @param data object returned from @link Ext.ux.grid.FiltersFeature.getFilterData
*/
unSerialArg: function(data){
var value={};
if (data.type == 'numeric'){
value[data.comparison] = data.value;
}
else {
value =data.value;
}
return value;


},


/**
* if the menu have not been created, force it's creation
*/
forceMenuCreation: function(){
var gridMenu = this.view.headerCt.getMenu();
this.onMenuCreate(this.headerCt, gridMenu);
}


and in my grids, I'm listening to the afterrender method and my the setFilterData method

Christiand
25 Apr 2012, 5:39 AM
looking into it, unSerialArg method is only for strings and int. I have not touched other data types. So you may have to improve this.