Results 1 to 3 of 3

Thread: Apply Grid List Filter manually

  1. #1
    Ext JS Premium Member
    Join Date
    Feb 2011
    Posts
    56
    Answers
    2

    Question Apply Grid List Filter manually

    Hi,

    in ExtJS 5 I can apply a Grid String Filter this way:

    Code:
    var column = view.columnManager.getColumns()[1];
    column.filter.setValue('E');
    column.filter.setActive(true)
    How can I apply a List Filter manually?

    My column:

    Code:
    {
            header : 'state',
            dataIndex : 'state',
            sortable : false,
            flex : 1,
            filter : {
                type : 'list',
                labelField : 'name',
                options : [ {
                    id : '11',
                    name : 'active'
                }, {
                    id : '12',
                    name : 'down'
                } ]
            }
        }

  2. #2
    Sencha User
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165
    Answers
    505

    Default

    Hi,

    Setting the gridfilters programmatically isn't supported in the API, but I have opened a feature request for you internally (EXTJS-15531).

  3. #3
    Sencha Premium Member
    Join Date
    Jul 2014
    Location
    Gilbert, AZ
    Posts
    12

    Default

    Here is a fiddle that overrides the List Filter and allows setValue('myValue'), setValue(['myValue1','myValue2']) or setValue([]):

    https://fiddle.sencha.com/#view/editor&fiddle/2pcm

    This fiddle could close out EXTJS-15531. Maybe sometime after ExtJS 6.7.0.

    Here is the code, just use 'programmaticList' for filter type:



    Code:
    Ext.define('Part.grid.filters.filter.ProgrammaticList', {
        extend: 'Ext.grid.filters.filter.List',
        alias: 'grid.filter.programmaticList',
    
        /**
         * @private
         * @method setValue
         * Method to set/clear values for list filter and update store filters if necessary
         * @param {Object} value Can be array or string to set many or one values.
         */
        setValue: function (value) {
            var me = this,
                menu = me.menu;
    
            if (Ext.isEmpty(value)) {
                value = [];
            } else if (!Ext.isArray(value)) {
                value = [value];
            }
    
    
            // The store filter will be updated, but we don't want to recreate the list store or the menu items in the
            // onDataChanged listener so we need to set this flag.
            // It will be reset in the onDatachanged listener when the store has filtered.
            me.preventDefault = true;
    
            if(menu) {
                var i, len, checkItem;
                var items = menu.items;
                for (i = 0, len = items.length; i < len; i++) {
                    checkItem = items.getAt(i);
    
                    if (checkItem.checked) {
                        value.push(checkItem.value);
                    }
                }
            }
    
            // Only update the store if the value has changed
            if (!Ext.Array.equals(value, me.filter.getValue())) {
                me.filter.setValue(value);
                len = value.length;
    
                if (len && me.active) {
                    me.updateStoreFilter();
                } else {
                    me.setActive(!!len);
                }
            }
    
        }
    });
    
    
    
    
    Last edited by russ396; 29 Jan 2019 at 5:54 AM. Reason: Code formatting

Posting Permissions

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