Store filter strange behavior

  1. #1

    Store filter strange behavior

    Hello

    I'm not sure if this is a bug or my stupidity - maybe there is something I oversee

    function test() {
    		var data = [
    			{ Id: 1, Name: 'Name1' }, { Id: 2, Name: 'Name2' }
    		];
    
    		Ext.define('Model1', {
    			extend: 'Ext.data.Model',
    			fields:['Id','Name'],
    			idProperty: 'Id'
    		});
    
    		var store = new Ext.data.Store({
    			proxy: { type: 'memory' },
    			model:'Model1',
    			data:data,
    			filters: [
    				function (item) {
    					return item.get('Id') == 1;
    				}
    			]
    		});
    
    			console.info(store.getCount());
    			store.clearFilter();
    			console.info(store.getCount()); // I would expect 2 here? - returned 1 - looks like store is still fitlered?
    
    		console.info(store.query('Name', 'Name1').getCount());
    		console.info(store.query('Name', 'Name2').getCount()); // I would expect 1 here, returned 0
    
    			var store2 = new Ext.data.Store({
    				proxy: { type: 'memory' },
    				model: 'Model1',
    				data: data
    
    
    			});
    
    			store2.filterBy(function (item) {
    			
    			return item.get('Id') == 1;
    		});
    
    		console.info(store2.getCount());
    		store2.clearFilter();
    		console.info(store2.getCount()); // correctly returns 2
    	}
    	Ext.onReady(test);
    tested on ExtJS 4.2.1.883 (Ext.net 2.5.0.30649)


    note that another strange thing is if I bind store2 to editable combobox filter disappear as long as user type somethign in combobox, while with store1, filter is still there regardeless what user type in

    Please let me know it this is a bug of feature

    Z
  2. #2
    Hi @Zdenek,

    Yes, that is a known bug - Store clearFilter doesn't work with initial filters.

    A workaround could be like this.
    store.clearFilter();
    store.loadData(data);
  3. #3
    OK
    the problem that query method does not return filtered records - it's still the same bug?

    Thanks
    Z
  4. #4
    Yes, it is related. A Store's clearFilter call somehow doesn't "return" excluded records.

    I recommend not to use a Store's filters as a config option.

    A filterBy call after instantiating of a Store is a good workaround, I think.

Similar Threads

  1. Strange behavior after nuget
    By bovo13 in forum 2.x Help
    Replies: 7
    Last Post: Oct 17, 2013, 1:21 PM
  2. Strange Button DirectEvent Behavior
    By Doug.Morrow in forum 2.x Help
    Replies: 2
    Last Post: Sep 03, 2012, 6:53 PM
  3. [CLOSED] RowExpander strange behavior
    By FAS in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Apr 24, 2012, 7:37 PM
  4. Strange behavior of buttons and itextsharp
    By bovo13 in forum 1.x Help
    Replies: 3
    Last Post: Dec 22, 2011, 6:53 AM
  5. [CLOSED] Strange behavior of fieldset
    By 78fede78 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 20, 2010, 11:55 AM

Posting Permissions