-
My goal: Use default filters with both AND and OR operators at the same time
-
Issue: The current default filters only have AND or OR as operators
-
Steps I've taken to troubleshoot:
Ive tried to make a JS script which looks like this
table12.setFilterStack({
filters: [
{
filters: [
{
columnId: "title_status",
operator: "=",
value: "Present"
},
{
columnId: "title_status",
operator: "=",
value: "Remind"
}
],
operator: "or"
},
{
columnId: "title_received",
operator: "isNotEmpty"
}
],
operator: "and"
});It works, but I’m not able to run that script when I switch tabs. I need either to make this script work, or somehow use both operators in the default filters.
-
Additional info: (Cloud or Self-hosted, Screenshots) Self hosted
Hey @appbuildernyc,
If you're using a JS query to set the filterStack for applying AND/OR filters by default, you can run that script in the success event of the table’s source query. This way, whenever the source query runs, the default filter will automatically be applied.
Hey,
Thanks for your reply!
Thank you, that sounds like a legit workaround!
Im just curious why we are having only one operator in the default filters and what’s the best practice to have default filters with both AND and OR operators. Is it JS query?
Great question! @appbuildernyc
By default, Retool only allows a single operator in the built-in filter UI because it’s designed for simple filtering. If you need a combination of AND and OR filters, the best practice is indeed to handle it through a JS query or through logic in your source query.
Using a JS query to set the filterStack gives you full control—you can define multiple conditions with mixed operators and then run that script on the success event of the table’s source query so the filters apply automatically each time.
Thanks again.
It works for me.