Ok, I just discovered Table.setFilter(). Had to refresh the docs to see it so I don’t know when it dropped. Thought I’d throw out some lessons learned from playing with it for a bit.
First, there is an error in the docs. You use operator not operation to set your comparer.
Second, it is not reactive. I tried to set the filters property using the value of a dropdown and changing the dropdown did not change the filter.
Now onto the good news. Rather than requerying your dataset you can filter it like this query that is triggered by my selProductTypeRight drop down:
Thanks for the tip on adding a filter. Here is my code for doing multiple filters. I think I need to remove a filter if one of my parameters is empty so I have to rebuild it for every change anyway. If anyone has a better way, I am all ears!:
var filters = []
if (selProductTypeRight.value) {
filters.push({columnName: "product_type_id", filterValue: String(selProductTypeRight.value), operator: "equals"})
}
if (selTownRight.value) {
filters.push({columnName: "town_id", filterValue: String(selTownRight.value), operator: "equals"})
}
if (txtProductNameRight.value) {
filters.push({columnName: "product_name", filterValue: txtProductNameRight.value, operator: "contains"})
}
tblProductsRight.setFilters(filters)
A couple more notes.
It looks like there is currently no way to set the filterStackType (or or and searches).
The one thing I cannot currently do with filters which I often do in my SQL queries is: product_type=x and (product_name like y or product_description like y). File that in feature requests though that seems like it would require a significant (read: breaking) architecture change within the filtering module.
And a little UI filter bug I noticed while playing. If you change the filter type in the UI it does not change the filtered results. If you add a filter or remove an existing filter the filtering is triggered with the new filter type.
Yeah, unfortunately this is not possible within the current architecture, but we are working on improving a lot of our components, so there is a possibility of a Table V2 in the future with additional functionality like this!
filterValue should be a single string, so for a multi-select component you will need to add multiple filters. Something like the following would probably work here
I am not sure I understand. Do you mean that it is not possible to use both and and or filters at the same time? If so, yes, this is currently a limitation of the table filters 😞 Usually we recommend implementing more complex filters outside of the table UI at this time, but I have taken a note of this as an item to address in the upcoming table overhaul 👍
There is a new table filter in development that will support more broad customizability, but I don't have a timeline on when it will launch yet. You'll be able to arbitrarily create filter groups in the UI there, and is likely to look similar to this when live: