Default Table Search Values

I’d like to show no records for a particular table when a user initially opens a page but user enters for example “1234” in the search field, all data containing “1234” is shown. If they hit “reset” all data is cleared and the empty grid/table text shows “No Records Found…”

A work around would be to set the initial default search value to something like “xyz123” which assuming nothing in the table has this, would show “No Records Found…” If user enters “1234” and all data containing “1234” is shown. If they hit “reset”, default value of “xyz123” would be applied again showing “No Records Found”

Any and all help with a script to accomplish either above scenarios, would greatly be appreciated…

Try a search view.

1 Like

Thanks Peter for your reply… For various reasons, I’m trying to REPLACE a current search view.

Gotcha. Let us know if you find a solution.

Hoping to get a solution that will be posted on this forum.

Hi, Jon!

Thank you for sharing your question here!

Is your end goal to only provide data of the records that matches certain criteria? I’m asking this because you could apply filters to the data source of the Grid view to only show specific records that match certain criteria and still allow users to utilize the keyword search to the “already filtered” data.

You can find more information Source Settings here. Feel free to reach out to our support team as well if you need help accomplishing your goal. They will be happy to assist you!

Happy Knacking! :slight_smile:

Hi Les, thank you for your response. My goal for various reasons is to replace a search view with grid/table view and I want to set this particular view to have a default data setting when page is opened to show the table as blank, similar to the way a search view is shown when opened. I would still like to allow the user to enter in a search criteria in the search field and if there is a match, show it. If user presses “reset”, it clears table and default value is shown. I would like set the default value as blank (null) or some crazy value (ie. “XYZ123”). Either one will show a message of “No Records Found…”

Of course, I’m happy to help!

There isn’t a setting within Knack to accomplish what you’re looking for as far as the page initially loading with no data, and then once your users apply an input into the keyword search, have the data load then. As you shared in your initial post, there could be a script someone here in the forum shares to implement to your custom code section of your app settings to accomplish that.

However, you can apply source filters to the Grid view (formerly called a Table view) to only display records that match a certain set of criteria, but the view in the Live app will display the data upon rendering the page.

You can also set default filters of your liking so that your users can filter the data with only that criteria that you set for each filter: see article here for more info.

Disabling the keyword search in the Settings section of the Grid view so that your users could only utilize the default filters that you have set is also an option. I believe that with the combination of default filters, data source filters, and custom code to accomplish initially loading the page with no data you could have this setup implemented within your app.

If you decide to reach out to our support team, they could take a look at your app directly (and if you choose, the data you’re hoping to filter) and help you with the default filters, data source filters, etc. in the event that you find this information not helpful.

Happy Knack building, and thank you again for sharing!

Hi Les, I figured out how to clear the table of data and display “No Records Found” when initially viewed or when user presses “reset” but hoping somebody with some JS skills could help me with additional code that would allow data to be searched based on user’s input in search field.

With code below, if a user enters for example “main street” and there is 10 records containing “main street”, no records are shown in the table but it will say “showing 1 - 10” below search field.

HERE IS WHAT I’VE DONE SO FAR:

/* clears search table - displays “no records found” */
$(document).on(‘knack-view-render.view_785’, function(event, view, data) {
$(‘#view_785 .kn-table tbody’).html(‘No Records Found…’);
});

1 Like