选中复选框时筛选网格记录

时间:2013-10-11 15:05:35

标签: extjs extjs4.1

我有一个网格和相关的复选框。默认情况下,当网格加载时,它显示所有记录,但我想在选中复选框时过滤它,并在取消选中复选框时加载所有记录。基本上我只想显示解析日期等于“0001-01-01”的网格数据。我已经给出了下面的复选框代码和网格截图。

{
    xtype: 'checkboxfield',
    boxLabel: 'Filter by UN-Resolved',
    id:'chkBox',
    handler: function() {
        var store = Ext.getCmp('defGrid').getStore();
        if(Ext.getCmp('chkBox').getValue()){
            store.filterBy([
                {filterFn: function(item) {return item.get('ID') == 'Sales';{console.log(item);}}
            ]);
            if(filter.data.items[0].data.ResolvedDate === '0001-01-01')
                {console.log("I'm inside");}
        });
    }

enter image description here

1 个答案:

答案 0 :(得分:0)

我终于能够解决这个......代码如下......

{
   xtype: 'checkboxfield',
   boxLabel: 'Filter by UN-Resolved',
   id:'chkBox',
   handler: function() {
   var grid = Ext.getCmp('defGrid');
   var checked = Ext.getCmp('chkBox').getValue();                                          

        if(checked){
            if (grid.store!=undefined) {
                    grid.store.filterBy(function(record) {
                        //console.log(record.data.ResolvedDate);
                        return record.data.ResolvedDate === '0001-01-01' ;
                        });
                    grid.getView().refresh();
            }

        }
            else{
                var grid = Ext.getCmp('defGrid');
                grid.store.clearFilter(true);
                grid.getView().refresh();
            }
    }
}