Skip to content

Updating a filter programmatically is not easy #179

Description

@uap-universe

Current Behavior

When you try to update a filter, you probably want to use

this.source.setFilter([{
    field: 'timestamp',
    search: myquery,
}]);

Problem No. 1 : this erases all previous filter.

But that is solved by using addFilter, which updates existing filter or adds a new one:

this.source.addFilter([{
    field: 'timestamp',
    search: myquery,
}]);

But this leads to Problem No. 2 : this erases a possible filter function from the column settings.

That means, you are supposed to write something like this

this.source.addFilter([{
    field: 'timestamp',
    search: myquery,
    filter: DateFunctions.onTimestampFilter,
}]);

repeating the correct filter function from the column settings when updating the filter.

Expected Behavior

When you omit the optional filter field, the default filter from the column is used.

Why cannot we simply implement it?

Because the filter function is a setting of the column and the data source does not know anything about columns.

Possible solution?

Since the goal is to change the filter of the table it's probably best to add API to the table class which sets the filter query of the filter component which then trickles down to the DataSource.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions