[CLOSED] Workaround with FilterHeader (source, filter empty fields, filter by renderer value)

  1. #1

    [CLOSED] Workaround with FilterHeader (source, filter empty fields, filter by renderer value)

    Hello!

    FilterHeader plugin ( http://examples2.ext.net/#/GridPanel...ader/Overview/ ) allow to filter rows by each of field.
    I have several questions about it.
    1) Where can I find the plugin sources?

    2) How to filter null values?
    Following code doesn't work.
    Ext.net.FilterHeader.behaviour.addBehaviour("string", {
        name: "/",
    
        is: function (value) {
            return value == "/";
        },
    
        getValue: function (value) {
            return { value: value, valid: true };
        },
    
        match: function (recordValue, matchValue) {
            if (!recordValue) {
                console.log('r');
                return true;
            }
    
            return false;
        },
    
        isValid: function (value) {
            return true;
        },
    
        serialize: function (value) {
            return {
                type: "string",
                op: "/",
                value: value
            };
        }
    });
    Although match function returns true, it can filter empty values of string field, but cannot filter null-values. It looks like somewhere in next functions null values of value are ignored.

    3) There are fields with renderer (ColumnBase.Renderer.Handler = "return value == true ? 'Yes' : 'No';") in some grids. But filter works only on "1, 0, true, false" values. How to make filter work on defined renderer of column?
    Last edited by Daniil; Sep 17, 2014 at 10:53 AM. Reason: [CLOSED]
  2. #2
    Hi @centerinform,

    1) Where can I find the plugin sources?
    In SVN:
    http://svn.ext.net/premium/trunk/Ext...eader-debug.js

    2) How to filter null values?
    Please provide a test case and exact steps to reproduce.

    3) There are fields with renderer (ColumnBase.Renderer.Handler = "return value == true ? 'Yes' : 'No';") in some grids. But filter works only on "1, 0, true, false" values. How to make filter work on defined renderer of column?
    In the FilterHeader sources you will see the definition on the "boolean" filter. You can override it.
  3. #3
    Thank you for your answer. The source code has helped me to solve the first two problems.

    But I still have a question about the Renderer.
    I can override the definition on the "boolean" filter, because I always know that "false" is "No" and "true" is "Yes".
    In more complex cases, I do not know an exact match. For example, if the value of one column is replaced by the value of another column.

    Do I understand correctly about FilterHeader that there is no way to use the result, has been returned from the column renderer handler?
    Is it even possible to get to renderer values ​​of selected row's cells in JS?
  4. #4
    Yes, a FilterHeader deals with the Store's records, not with HTML rendered to the cells.

    You can call a Column's Renderer for a specific record.

    Please look at the Ext.view.Table's renderCell method.
    http://docs.sencha.com/extjs/4.2.1/s...hod-renderCell

    The method calls Columns' Renderers (if defined).
    if (column.renderer && column.renderer.call) {
        value = column.renderer.call(column.scope || me.ownerCt, fieldValue, cellValues, record, recordIndex, columnIndex, me.dataSource, me);
    Generally speaking, nothing stops you to call it inside the FilterHeader's behavior scripts to determine the Renderer's value.

    Another possible approach could be getting a value directly from cells (rendered HTML). Personally, I would try it first.
  5. #5
    Thanks for the help.

    The following override works for me:

    Ext.define("my.overridden.FilterHeader", {
        override: 'Ext.net.FilterHeader',
        
        isSmartFilterValid : function (field) {
            return true;
        },
    
        smartFilterValue: function (value, dataIndex, record, type, field) {
            var recordValue = record && record.get(dataIndex),
                isEmpty = Ext.isEmpty(value, false);
    
            var column = field.column;
            if (column && column.renderer && column.renderer.call) {
                recordValue = column.renderer.call(column.scope, recordValue, null, record);
            }
    
            if (isEmpty) {
                return true;
            }
    
            if (!type && (recordValue == null || !Ext.isDefined(recordValue))) {
                return false;
            }
    
            return this.selectSmartFilter(type, recordValue, value, field);
        }
    });

Similar Threads

  1. [CLOSED] Stringfilter --> Filter on empty
    By CarWise in forum 2.x Premium Help
    Replies: 4
    Last Post: Feb 07, 2014, 8:43 AM
  2. Replies: 7
    Last Post: Mar 12, 2013, 8:15 AM
  3. [CLOSED] GridPanel filter by the value returned by renderer
    By ermanni.info in forum 2.x Premium Help
    Replies: 19
    Last Post: Feb 16, 2013, 10:56 PM
  4. Replies: 2
    Last Post: May 01, 2012, 4:57 PM
  5. Remote Filter always empty with DataContext
    By JIGSAW in forum 1.x Help
    Replies: 0
    Last Post: Feb 25, 2011, 12:38 PM

Tags for this Thread

Posting Permissions