Filter in grid header extjs 6

大憨熊 提交于 2019-12-06 08:19:28

问题


How to create a filter in the grid headers?

I found this snippet: https://stackoverflow.com/a/22015160/5775332 and updated to compatibility with 6th version:

Ext.define('Fiddle.view.SearchTrigger', {
    extend: 'Ext.form.field.Text',
    alias: 'widget.searchtrigger',

    requires: [
        'Ext.form.trigger.Trigger'
    ],

    defaultListenerScope: true,

    triggers: {
        search: {
            handler: function(field, trigger, e) {
                this.setFilter(this.up().dataIndex, this.getValue());
            },
            cls: 'x-form-search-trigger'
        },
        clear: {
            handler: function(field, trigger, e) {
                this.setValue('');
                if(!this.autoSearch) this.setFilter(this.up().dataIndex, '');
            },
            cls: 'x-form-clear-trigger'
        }
    },
    listeners: {
        render: 'onTextfieldRender',
        change: 'onTextfieldChange'
    },

    onTextfieldRender: function(component, eOpts) {
        var me = this;
        me.ownerCt.on('resize', function(){
            me.setWidth(this.getEl().getWidth());
        });
    },

    onTextfieldChange: function(field, newValue, oldValue, eOpts) {
        if(this.autoSearch) this.setFilter(this.up().dataIndex, this.getValue());
    },

    setFilter: function(filterId, value) {
        var store = this.up('grid').getStore();
        if(value){
            store.removeFilter(filterId, false);
            var filter = {id: filterId, property: filterId, value: value};
            if(this.anyMatch) filter.anyMatch = this.anyMatch;
            if(this.caseSensitive) filter.caseSensitive = this.caseSensitive;
            if(this.exactMatch) filter.exactMatch = this.exactMatch;
            if(this.operator) filter.operator = this.operator;
            console.log(this.anyMatch, filter);
            store.addFilter(filter);
        } else {
            store.filters.removeAtKey(filterId);
            store.reload();
        }
    }

});

The most difficult place - creation items with widget in column. I cant reproduce it in Sencha Fiddle. How to do it?


回答1:


First login to Sencha Fiddle using the Sencha Forum credentials. After this, copy-paste your code and save it. The updated url that you get after saving will be sharable. Please refer here for docs on Sencha Fiddle.

Fixed code: https://fiddle.sencha.com/#view/editor&fiddle/2820



来源:https://stackoverflow.com/questions/46631002/filter-in-grid-header-extjs-6

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