how to use filter in ExtJs store?

后端 未结 1 1650
攒了一身酷
攒了一身酷 2021-02-06 06:19

I created a store using ExtJs and i want to load the value of store to ComboBox. But before loading values i need to filter some data based on value selected in another comboBox

相关标签:
1条回答
  • 2021-02-06 06:31

    According to Ext.data.Store filter method documentation:

    var stateId = 1; // your value
    cityStore.clearFilter(true);
    cityStore.filter('StateId', stateId);
    

    Update

    I've found that ComboBox filters data by itself and there is no opportunity to change it's behaviour. But I see two solutions of this problem:

    1. Filter data manually (see Ext.util.MixedCollection filter) and load it into your store (see Ext.data.Store load)

    2. Disable store's clearFilter and filter methods and use own cityFilter:

      Ext.define('CityStore', {
          extend: 'Ext.data.Store',
          filter: Ext.emptyFn,
          clearFilter: Ext.emptyFn,
          cityFilter: function (stateId) {
              Ext.data.Store.prototype.clearFilter.call(this);
              Ext.data.Store.prototype.filter.call(this, 'StateId', stateId);
          }
      });
      

      Then use cityFilter() method.

    0 讨论(0)
提交回复
热议问题