Extjs 4.1.3 button that sets active filters

橙三吉。 提交于 2019-12-24 20:10:04

问题


I want to add a button to the toolbar that automatically sets a filter as active and then subsequently filters the data. I have tried using the setActive() function for Ext 4.1.3 but that function is not being recognized.

fiddle

Code

var openButton = Ext.create('Ext.Button', {
            text: 'Open Topics',
            handler: function () {
                grid[uniqueId].filters.setActive('Open/Current');
            }
        });

...
var columns = [{
    text: 'Status',
    width: 100,
    dataIndex: 'TopicStateValue',
    filter: {
        type: 'list',
        options: ['Open/Current', 'Archived/Closed', 'Hold']
    }
}
...

回答1:


The setActive method can't be found in the location you look for it. You're trying to execute setActive on a list of filters, but the actual function can only be executed once you have found the specific filter object.

In your example code (the Fiddle is of no use as you skipped the column in question there) you would get the filter first like this:

var filter = grid[uniqueId].filters.getFilter('TopicStateValue');
filter.setActive(true);

However activating the filter doesn't do what you expect it to do. It will merely enable the filter UI element in the filters bar. To execute said filter automatically after enabling it you need to set the Value for that filter:

filter.setValue('Open/Current');

If you're not using the filters bar or don't want to show this particular filter dropdown to the user at all, you're better off filtering the store directly:

var store = grid[uniqueId].getStore();
store.filterBy(function(item) {
    return item.TopicStateValue == 'Open/Current';
});


来源:https://stackoverflow.com/questions/45380114/extjs-4-1-3-button-that-sets-active-filters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!