PDA

View Full Version : Ext.ux.grid.FiltersFeature: getFilter() is undefined



Nameless11
14 May 2011, 2:05 AM
Dear Community,

I'm new to ExtJS and I'm facing some problems with Ext.ux.grid.FiltersFeature.
I have a grid with Filter feature:


Ext.define('AM.view.book.ListOzon' ,{
extend: 'Ext.grid.Panel',
alias : 'widget.booklistozon',
title : 'Books grid',
store: 'BooksOzon',
features: [{
ftype: 'filters',
encode: true,
local: true,
autoReload: false,
filters: [{
type: 'numeric',
dataIndex: 'id'
},{
type: 'string',
dataIndex: 'author'
},{
type: 'string',
dataIndex: 'name'
}]
}],
columns: [{
header: 'Id',
dataIndex: 'id',
width: 70
},{
header: 'Author',
dataIndex: 'author',
flex: 2
},{
header: 'Book Title',
dataIndex: 'name',
flex: 3
}]
});


I need to activate filter with some value by a button from outside a grid.
I'm using the following code for a button click handler:


var bookListOzon = this.getBookListOzon();
bookListOzon.filters.clearFilters();
var filterId = bookListOzon.filters.getFilter('author');
filterId.setValue('author_2');
filterId.setActive(true);
bookListOzon.filters.reload();


It works well after filter is activated manually for 'author' column (e.g. ='author_1').
But if I try to click a button when filter is not set manually before, I got an error since bookListOzon.filters.getFilter('author') is undefined.

It seems to me this behavior is not correct. How can I set a value for a filter if it wasn't filled with some value before?

carmeloferrante
16 Jun 2011, 3:33 AM
It tooks me a long time too, this night.
In the end I found that this code should work:
(change mygrid with the name of your grid)


mygrid.filters.addFilter({dataIndex: 'author', type: 'string', value: 'author_2'});
mygrid.store.load();


If you prefer you can even use


mygrid.filters.reload();

insetad of


mygrid.store.load();

To preserve the local or remote filtering settings
Make us know if it worked for you too!

Have a nice day!

freshyseth
9 Sep 2011, 12:42 PM
I was able to get this working via a button. I'm about to tie it in with some checkbox functionality which brings up an issue I've been having. Right now whenever I addFilter to a grid's store the filters are applied using an AND condition. How do I apply filters using the OR condition?

For instance, using the FiltersFeatures.js bound to columns in a datagrid I can select two options from a list in a single column and the filters does Option1 OR Option2. It even does ORs for other columns as well.

So, how do I do that by programatically adding the filters?

Thanks!