Search bar query for Google Sheets to limit results

I've progressed by building out the javascript code needed to limit the list.
This works successfully when the code is added to the "transform results" field of the Get Data query.

However, I now need to work out how to "refresh" the list if the search text changes.

I.e. currently I have a full list of say 50 items. Then I type in a search query and the results are limited to that query (say 10) but then the original list of 50 has been reduced to 10. So a secondary search (or removal of search term) doesn't show me the full list again.

The search continues!

function filterListBySearch(list, searchInput) {
  if (!searchInput) {
    return list;
  }

  return list.filter(function(item) {
    return Object.values(item).some(function(value) {
      return String(value).toLowerCase().includes(searchInput.toLowerCase());
    });
  });
}

return filterListBySearch({{ getBricks.data }}, {{ searchBar1.value }});


Edit: The right code, but the wrong location. Instead of using this to transform the results, create a seperate transformer and then use that as the data source for the table itself.

Thanks a lot for your help @ScottR - Very much appreciated.

1 Like