Articles in this section
Category / Section

How to Dynamically Generate Titles for Widgets?

Published:

Creating dynamic titles in widgets can provide a more interactive and timely user experience. This article will guide you through the process of generating widget titles based on the filter value chosen. Here, for demonstration purposes, we have taken a combo box widget, the title of this widget automatically displays the filtered value which is current or next month achieved through Expression using SQL and PostgreSQL.

SQL Syntax for Current and Next Month Using Expression Option

To generate a dynamic title based on the current or next month in SQL, you can use the DATENAME functionality available in expression option of data source designer. This function extracts the name of the month from a date value. The syntax for SQL Server is as follows:

Current Month:
DATENAME(month, GETDATE())

image.png

This expression will return the name of the current month based on the datetime settings of your SQL database installed machine.

Next Month:
DATENAME(month, DATEADD(month, 1, GETDATE()))

image.png

This expression will return the name of the next month.

Using Database Column:

If you want to extract the month name from a specific date column in your database, you can use the following syntax:

DATENAME(month, ([Date]))

image.png

Replace [Date] with your database column name that contains the date field.

PostgreSQL Syntax for Current Month Using Expression Option

For PostgreSQL, the syntax differs slightly. You will use the TO_CHAR function to format the current date as a month name string in the expression dialog box of data source designer.

Current Month:

TO_CHAR(CURRENT_DATE, 'Month')

This will return the current month name based on the datetime settings of your Postgres SQL database installed machine.

Using Database Column:

To extract the month name from a date column in PostgreSQL, use the following syntax:

TO_CHAR([Date], 'Month')

Again, replace [Date] with the name of your date column.

Implementing the Dynamic Title

After crafting the expression, you need to utilize the ‘label’ parameter within your title to display the precise value. Please refer to the help documentation to know more about it. For instance, if you are creating a widget in a dashboard, you can set the title as follows:

Current Month : {{:CurrentMonth}}

image.png

Here, CurrentMonth is the name of the expression you have defined using the syntax provided above.

image.png

Additional References

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
SM
Written by Soundarya Mani Meharan
Updated:
Comments (0)
Please  to leave a comment
Access denied
Access denied