Pass string to table's search with javascript?

  • 1
  • Question
  • Updated 2 years ago
Is there a way to pass a string to a table's search bar when the table renders?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
^^
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
There really is not a supported way to do this now.  The searchbox has a class, which can be found from the component, and be manipulated using jQuery.  So theoretically you could add text to the class.   Getting the search to atcually be effective would be an entirely different problem...

You can pre-fill filter values by adding parameters to your URL string.  This may work for you.  If you have a condition named "type" append  "&type=foo" to your URL and the page will be filtered to foo. 
Photo of Louis Skelton

Louis Skelton

  • 4,878 Points 4k badge 2x thumb
I know this is an old one, but I had to do this recently and used jQuery's .change() method on the searchbox to force the table to process the search. For example:

// Insert value into search box
$(".searchbox").val("Value to put into search box");
    
// Cause searchbox to update and run search on table
$(".searchbox").change();
(Edited)