top of page

Search Component Tips

The power of search components in Knack applications is immense. These tools allow users to filter records based on custom parameters easily. For example, you can view only the "pending" records or quickly switch back to see all records.


Thank you to Craig Winnall for providing this valuable snippet of JavaScript, which enhances search capabilities in Knack applications.


Sign up to Knack for Free - Affiliate Link


Add to JavaScript

/*Pre Filtering Search view using URL*/
  Knack.router.on('route:viewScene', function (slug) {
    if (slug) {
      if (slug.includes('client-search')) {
        const url = 'https://chprojectsupportltd.knack.com/classic-clips#clients/client-search/?view_614_page=1&view_614_filters=%5B%7B%22field%22%3A%22field_403%22%2C%22operator%22%3A%22in%22%2C%22value%22%3A%5B%22Pending%22%5D%7D%5D';
        window.location.href = url;
      }
    }
  });

This JavaScript code snippet listens for a specific route change in a Knack application, specifically when the user navigates to a scene with the slug 'client-search'.


Upon detecting this route, the code checks if the slug contains 'client-search'. If it does, it redirects the user to a predefined URL that automatically applies a filter to display only the records with a status of "Pending" in the "client-search" view.


In summary, this code facilitates pre-filtering of search results based on the specified status, enhancing the user experience by displaying relevant data immediately when users access the search view.


Replace the highlighted code with your page slug and the filtered page URL


Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
  • Black LinkedIn Icon
  • Black Twitter Icon
  • Youtube

©2022 CH Project Support Limited

bottom of page