angular2-smart-table icon indicating copy to clipboard operation
angular2-smart-table copied to clipboard

Updating a filter programmatically is not easy

Open uap-universe opened this issue 9 months ago • 0 comments

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.

uap-universe avatar Jan 23 '25 18:01 uap-universe