Tips & Tricks- using search and filter in the same list

Being able to search or filter a list is really helpful, especially when you have a long list of products, customers or items. Search is great when you know what you looking for, it helps you find it quickly, while using a filter groups or categorizes items making it easier to browse the category you looking for, for example, customers vs prospects. Good thing is you can create a list with both a search and filter field. Here is an example of my list of accounts from Salesforce. I added a search field to quickly find a specific account and a filter field to categorize the prospects and my direct customers.


You might run into the scenario like I did where your filter is working and search is not or the other way round. The trick is to make sure your query and query parameters reference filter and search in the same order. Meaning if your query defines the filter first then the query parameter must have filter first. Sounds simple enough but can catch you out easily.
Here is my code snippet with the incorrect order, in my query I had search first and then filter while my query parameters had filter first.

query: SELECT id, '$.Name', '$.Type', '$.BillingCountry' FROM [Account] WHERE ('$.Name' LIKE '%'||@search||'%' OR @search IS NULL) AND ('$.Type' LIKE @filter OR @filter IS NULL) 
      queryParameters: 
       filter: =@ctx.components.account-list.state.filter
       search: =@ctx.components.account-list.state.searchText

Here is the correct code for the query with search being first in both the query and the query parameters.

 query: SELECT id, '$.Name', '$.Type', '$.BillingCountry' FROM [Account] WHERE ('$.Name' LIKE '%'||@search||'%' OR @search IS NULL) AND ('$.Type' LIKE @filter OR @filter IS NULL) 
      queryParameters: 
       search: =@ctx.components.account-list.state.searchText
       filter: =@ctx.components.account-list.state.filter
1 Like