Results 1 to 2 of 2

Thread: How to create reusable gridpanel filter?

  1. #1
    Sencha Premium User
    Join Date
    Jan 2020
    Posts
    1

    Default How to create reusable gridpanel filter?

    Hi,

    I have a gridpanel in a class like this:

    Code:
    Ext.define('MifAdmin.view.ministry.Ministries',{
        extend: 'Ext.tab.Panel',
        xtype: 'ministries',
    
    
        items: [{
                xtype: 'gridpanel',
                title: 'Ministries',
                plugins: 'gridfilters',
                bind: {
                    store: '{ministries}'
                },
                scrollable: false,
                columns: [{
                        xtype: 'gridcolumn',
                        dataIndex: 'ministryName',
                        text: 'Ministry Name',
                        filter: {
                            type: 'string',
                            itemDefaults: {
                                enableKeyEvents: false,
                                listeners: {
                                    buffer: 1000,
                                    change: function (field, e) {
                                        var f = this.up('gridcolumn').filter;
                                        f.setValue(f.getValue(field)); 
                                    }
                                }
                            }
                        }
                    }
                    ...
    I want to reuse the same filter for multiple columns. Something like this:
    Code:
    ...
    columns: [{
        xtype: 'gridcolumn',
        dataIndex: 'ministryName',
        text: 'Ministry Name',
        filter: defaultStringFilter
    },{
        xtype: 'gridcolumn',
        dataIndex: 'primaryContact',
        text: 'Primary Contact',
        filter: defaultStringFilter
    }
    ...


    What is the best way to accomplish this? I have tried several things and they are not working. I would like to see how to do this 1) By defining the filter for use just within this class and 2) Defining a filter that could be used across multiple classes.

    Thanks.

  2. #2
    Sencha User
    Join Date
    Oct 2018
    Location
    Noida
    Posts
    67

    Default

    Hi,

    You can return that filter object from a function and call that function many time you want for different columns.
    Check the solution in the fiddle - https://fiddle.sencha.com/#fiddle/33v3&view/editor

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •