Discuss

Show a Message when Query Returns No Results

On this page

In some cases your query may return no results so it is useful to be able to show a message, telling the users no results are returned. In Wappler this can be done using the dynamic show/hide attributes.

We have a page, which lists records from a database query. We added a title above our records and we will configure this title to only show when no records are returned:

Screenshot_36|690x392

Click the element you want to show (in our case this is a title, but can be any other HTML element) and then add new dynamic attribute:

Screenshot_37|690x392

Open the display category and select show:

Screenshot_38|690x392

Then click the dynamic data picker, to select a condition when to show this message:

Screenshot_39|690x392

Select the query, which returns your results(1) and click the data formatter icon(2):

Screenshot_40|690x392

Screenshot_41|690x392

Right click the expression, and from the Conditional menu, select Has Items:

Screenshot_41|690x392

Click the select button to apply this formatting option:

Screenshot_42|690x392

Currently the condition checks if the query has items and if we leave it like that, it will show the message when the query returns records. However we need it to show when the query returns no items. All we have to do is to add an ! before the expression, like !serverconnect1.data.query1.hasItems():

Screenshot_43|690x392

And we are done. The message saying "no items" will only be displayed when the query returns no results.

TIP: To avoid showing the "No results found" message before the data on your page is loaded, you can use the Page Loader: https://community.wappler.io/t/applying-a-page-preloader/2875


WapplerPrevious|101x31   WapplerNext|77x31