I've got a table with a search bar which will filter the table only when the search is submitted, as I don't want to trigger queries on every keystroke. However, I would like the table to show all of the rows as soon as the search term is deleted or cleared, without having to press Enter afterwards.
I've got it working at the moment but I'm just wondering if there is a simpler way that I'm missing (I'm new to all of this!)
Currently, the table is initially populated by query1.data (no filtering) which runs when the search bar text (textinput1.value) changes, but is disabled when textinput1.value.length > 0.
When textinput1 is submitted, it triggers query2 which runs the filter query.
After either query runs, it triggers a JS script which does a table1.setData to either query1.data or query2.data depending on whether textinput1.value.length > 0 or not.
This way the search runs when something is typed in and Enter is pressed, but will reset to the unfiltered view when the search term is deleted. Would just like to know if there's a simpler solution as I'm going to need this functionality a fair bit.