Page 1 of 1

Can filterbar have multiple value initialized

Posted: Mon Jun 07, 2021 9:36 am
by janan

https://www.bryntum.com/examples/grid/filterbar/

In the above example is it possible to initialize filter bar with all the values in filter items.
Image


Re: Can filterbar have multiple value initialized

Posted: Mon Jun 07, 2021 1:54 pm
by pmiklashevich

Hello,

It's a bit tricky, but doable. You need to configure initial filter. And since the filter allows multiple values, you need to define the default filter function:

    features : {
        filterBar : {
            compactMode : false,
            filter      : {
                property : 'city',
                value    : ['Paris', 'Barcelona'],
                filterBy(record) {
                    return !this.value.length || this.value.includes(record.city);
                }
            }
        },

Then also need to specify values for the combo field used for filtering and the filtering function.

            filterable : {
                // filterField : cityCombo,
                filterField : Object.assign(cityCombo, {
                    value : ['Paris', 'Barcelona']
                }),
                filterFn : ({ record, value }) => !value.length || value.includes(record.city)
            }

Opened a ticket to avoid code duplication: https://github.com/bryntum/support/issues/2993