Filtering Query Results after the query

Hello all! Hopefully you can help me with something. I have a dynamic page that I would like to display information from a different dataset on. For this particular page and data model reference fields won’t do the trick. What I was thinking was a query on page load (works great and is fast). My issue is I want to have an option where they could search the query results without re-executing a query. Is there a way that once the query runs and I have the information displaying in the repeater they could search it from there? Would a filter on the results do this? Can they search more than once? Any help would be great.

1 Like

Hey,

I needed to filter my results after running a query. the best I could do would be to simply foreach the result items of the query;

async function filter_query(needle, haystack){
  for (var i = 0; i < haystack.length; i++) {
      var strand = haystack[i];
      if(strand.column === needle){
          return strand;
          break;
      }
  }
 }

for your case I would suggest using an Array filter with a text input and run on blur or change of input:

var query_results = run_query(), //<-- this would be your pre queried results
    filter_value = text_input.value; //< -- your "needle" to match

let filtered_results = query_results.items.filter((currentValue) => {
    if(currentValue.myField === filter_value) 
        return currentValue;
}, column_heading_value);

you could use any expression in the if statement but would poss need some regex depending on your matching requirements;

Then all you need to do is update the repeaters data with filtered_results.