How to set default operator for Condition Filter only?

Posted by: pkim on 2 March 2020, 6:11 pm EST

    • Post Options:
    • Link

    Posted 2 March 2020, 6:11 pm EST

    Hello,

    I am trying to get column filters to behave a certain way:

    1. Disable Value filters / only show Condition filters
    2. Set the Condition filter’s default operator to ‘Contains’ instead of ‘(not set)’ upon opening the column condition filter
    3. Persist column filter settings throughout a user session

    I know I can set a FlexGridFilter’s FilterType to ‘Condition’ only, and I can set an operator from inside a FlexGridFilter’s filterChanging event handler (following example from https://www.grapecity.com/wijmo/api/classes/wijmo_grid_filter.flexgridfilter.html#filterchanging). But sometimes the operator still inconsistently shows ‘(not set)’ even though I set it to ‘Contains’.

    From my testing, the default operator appears correctly if I open a column filter that has both a Condition Filter and Value Filter; in these cases it opens the Value Filter by default, forcing me to click the Condition Filter to see its operator value which appears correctly. However if I open a column filter that only has a Condition Filter, then the default operator still incorrectly appears as ‘(not set)’; if I reopen that same filter, the operator value then correctly appears as ‘Contains’ instead of ‘(not set)’. It appears as if the internal operator value is set to ‘Contains’, but I need to “refresh” the display text to see that value, which is why reopening a Condition-only-filter shows the correct operator value, and a column filter with both Condition and Value filters will show the correct operator value after I click the Condition filter mode.

    Can I get assistance to make the column filters behave as stated above? Some column filters will have both Condition and Value filters, while others will only have Condition filters. But in either case, when I open the column filter, I want the default operator for Condition Filter to show ‘Contains’ instead of ‘(not set)’.

  • Posted 3 March 2020, 1:00 am EST

    Hi Paul,

    This is expected because the filterChanging event is fired after the editor is updated with the current filter settings. So, setting the operator in the filterChanging event does not update the editor. You can use the updateEditor method of the ColumnFilterEditor class to update the editor manually. Please refer to the sample link below:

    [urlhttps://stackblitz.com/edit/js-kmrnyo

    https://www.grapecity.com/wijmo/api/classes/wijmo_grid_filter.columnfiltereditor.html#updateeditor

    Regards,

    Ashwin

  • Posted 3 March 2020, 12:23 pm EST

    Hi Ashwin,

    Thanks for the reply, the behavior I want is working great now.

    I had a follow-up question out of curiosity. Is it possible to determine the available list of operators for a filter? I’m wondering if I can set different default operators for a Condition filter depending on whether the operator list is for strings, numbers, dates, or booleans. Looks like only stringOperators has ‘Contains’, so I’d like to set a different default operator for the other types if possible.

    Thanks again,

    Paul

  • Posted 3 March 2020, 11:28 pm EST

    Hi Paul,

    We are sorry but there is no direct way to check which operators can be used for which type of column. But, you can still explicitly set the default according to the dataType of the column:

    filter.filterChanging.addHandler((s, e) => {
      if(grid.columns[e.col].dataType === wjcCore.DataType.Number) {
        var colFilter = filter.getColumnFilter(e.col);
        if(!colFilter.conditionFilter.isActive) {
          colFilter.conditionFilter.condition1.operator = wjcGridFilter.Operator.GT; // greater than operator for number columns
        }
      }
    });
    

    https://stackblitz.com/edit/js-aqqknb

    ~regards

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels