How to add filters in grid column headers in extjs?

纵饮孤独 提交于 2019-12-04 15:41:41

This is an example:

Ext.define('Webdesktop.view.admin.List', {
extend: 'Ext.grid.Panel',
alias: 'widget.admin_casoslist',
initComponent: function() {
    var me = this,
    filters = {
        ftype: 'filters',
        encode: false,
        local: true
    };

    Ext.apply(me, {
        title: 'gridTitle',
        store: List_CasSos_Store,

        filterable: true,
        features: [filters],
        closable: true, // fixme: need to set here, because has no effect in tabpanel defaults configuration
        autoScroll: true,
        columns: {
            items:[
            {
                text: 'header1',
                filter: {
                    type: 'string'
                },
                flex: 1,
                dataIndex: 'relation_patron_paraine'
            },{
                text:'header2',
                filter: {
                    type: 'list',
                    options: ['case4', 'case3', 'case2', 'case1']
                },
                hidden:true,
                flex: 1,
                dataIndex: 'etatsante'
            },{
                text:'header3',
                filter: {
                    type: 'numeric'
                },
                hidden:true,
                flex: 1,
                dataIndex: 'revenumnsuel'
            }
            ],
            defaults : {
                align: 'center'
            }
        }
    });
    me.callParent();
}

In the controller:

uses: [
   'Webdesktop.view.admin.List',
    ...
   'Ext.ux.grid.FiltersFeature'
    ]

You need to add this to your grid configuration:

plugins: [{
  ptype: 'gridfilters'
}],

And then in each column:

filter: {type: 'string', dataIndex: 'passengerFullName'},

Note that the filter is depended on store whether it will be a remote filter or a local filter.

See here for more info: http://docs.sencha.com/extjs/6.0.2-classic/Ext.grid.filters.Filters.html

To use filter in header of grid you need to declare array of filter and then give scope to grid. Then write

this.filters = new Ext.ux.grid.GridFilters({
            filters:this.filter
        }) ;

Give a plugin for that

this.plugins = [this.filters];

Where you adding column write

gridEl.filter{
        type: 'list',
        dataIndex: "DATAINDEX",
        local : local,
        dataForFilter : data
    };

One solution it's to capture the "column click" column, get the param that you want to filter and in the function put this filter on the Grid Store.

Column Example

{
    header      : "email",
    dataIndex   : 'email',
    listeners : {
        click: {
            element: 'el', //bind to the underlying el property on the panel
            fn: function(){ 
                storeGrid.filter("email", /\.com$/); // email
                            storeGrid.sort('myField', 'ASC');
            }
        }
    }
},

Sencha Filter: filter store

Sencha Sort: sort store data

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