Applying custom FlexGridFilter values when grid data changes

Posted by: natalie.rubin on 10 February 2020, 5:38 am EST

  • Posted 10 February 2020, 5:38 am EST

    How can I retain custom filter values when the grid data changes?

    The column I'm attempting to filter is actually an array of tag values, so I need to set the value filter's uniqueValues to the set of tags, not the actual data values - in other words, the values should be ["foo", "bar", "baz"] not ["foo", ["foo", "bar"], "baz"]. I have gotten this working on the initial load of the data, but when I change the underlying data, the filter resets to the values from the data, rather than the uniqueValues I've set.

    It seems like there's a grid event that I need to handle and put the custom filter code in the handler, but I can't figure out what it might be - refreshed and loadedRows put me in an infinite loop, and itemsSourceChanged seems to fire before the filter is updated internally. If I manually fire my custom filter code after a data change (by clicking a button), I get the filter values I expect.

    Here's an example showing the problem:
    https://stackblitz.com/edit/angular-qykqjt

    And here are some screenshots of the filter drop down:


    Thanks!
    Natalie
  • Marked as Answer

    Replied 10 February 2020, 5:13 pm EST

    Hi Natalie,

    The filterChanging event of the FlexGridFilter class can be used for your requirements. Set the uniqueValues property in the event handler of the above event:
    // filter.getColumnFilter('tags').valueFilter.uniqueValues = this.tags;
    filter.filterChanging.addHandler((s, e: wjcGrid.CellRangeEventArgs) => {
    if(s.grid.columns[e.col].binding === 'tags') {
    s.getColumnFilter('tags').valueFilter.uniqueValues = this.tags;
    }
    });

    You may refer to the updated sample below:

    https://stackblitz.com/edit/angular-2je3oe

    Regards,
    Ashwin
  • Replied 11 February 2020, 3:31 am EST

    Perfect. Thanks so much!
Need extra support?

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

Learn More

Forum Channels