PDA

View Full Version : Dynamic List Filter



vicvolk
23 Aug 2012, 2:01 AM
Hi, guys! Has anybody managed to implement dynamic list filter? Unfortunately, there is no even a simple example, using this feature. Now, I try to do it in the following manner. Firstly, I declare my store for a filter

var filterStore = Ext.create('Ext.data.Store', {
fields: ['text'],
autoLoad: false,
proxy: {
type: 'ajax',
url: './get/get_ref_store.php',
reader: 'json'
}
});


Then I declare my filters:



var filters = {
ftype: 'filters',
encode: encode,
local: local,
filters: [
{dataIndex:'attr_1_', type: 'list', store: filterStore}
///some other filters coming here
]


And finally I inject my filters to the grid. After that I see that my filter is populated with the values returned by the ajax-call. But if I check a particular value, the grid goes blank, as if there are no matches. Instead, if use options in a standard manner and populate my filter exactly with the same values, my grid is filtered nice.

Really need help! Many thanks.

vicvolk
23 Aug 2012, 12:58 PM
I made it work. I added modifications suggested by Wivern in this thread http://stackoverflow.com/questions/9086918/extjs-grid-filter-dynamic-listfilter/12088932#12088932 and besides added some extra code.


In ListMenu.js file I changed this



for (i = 0, len = records.length; i < len; i++) {
itemValue = records[i].get('id');
item = Ext.create('Ext.menu.CheckItem', {
text: records[i].get(me.labelField),
group: gid,
checked: Ext.Array.contains(me.selected, itemValue),
hideOnClick: false,
value: itemValue
});

item.on('checkchange', me.checkChange, me);

me.add(item);
}


To this




for (i = 0, len = records.length; i < len; i++) {
itemValue = records[i].get('id');


//New line of code

if(itemValue != records[i].get(me.labelField)) itemValue = records[i].get(me.labelField);

item = Ext.create('Ext.menu.CheckItem', {
text: records[i].get(me.labelField),
group: gid,
checked: Ext.Array.contains(me.selected, itemValue),
hideOnClick: false,
value: itemValue
});

item.on('checkchange', me.checkChange, me);

me.add(item);
}

scottmartin
23 Aug 2012, 4:39 PM
Thank you for the update.

Regards,
Scott.