cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 

Issue with HTML Table Styling in Databricks Alerts

VKe
New Contributor III

Hi Community,

Iā€™m trying to create an alert in Databricks with a custom email notification that includes the results of a SQL query displayed in an HTML table. However, I am facing issues with styling the table, specifically with adding borders and background colors to the headers.

Here is the HTML code I am currently using:

 

<table border="1" cellpadding="5" cellspacing="0">
  <tr style="background-color: black; color: white; font-weight: bold;">
    <th>Project Name</th>
    <th>Jira ID</th>
    <th>Category</th>
    <th>Site</th>
  </tr>
  <tbody>
    {{#QUERY_RESULT_ROWS}}
    <tr>
      <td>{{Project_Name}}</td>
      <td>{{Jira_ID}}</td>
      <td>{{Category_1}}</td>
      <td>{{Site}}</td>
    </tr>
    {{/QUERY_RESULT_ROWS}}
  </tbody>
</table>

 

The table renders correctly with the data, but the following issues persist:

  • Borders do not appear around the cells.
  • Background color for the header row doesnā€™t display.
  • Overall table styling (such as cellpadding and cellspacing) doesnā€™t seem to be applied.

I have tried several variations, including inline styles, but nothing seems to work. Is there a limitation with HTML and CSS in Databricks alerts, or am I missing something in the implementation?

Any guidance or solutions on how to display a properly styled table in the alert email would be greatly appreciated!

Thank you!

4 REPLIES 4

szymon_dybczak
Contributor III

Hi @VKe ,

That's because only subsets of html tags and attributes are supported in alerts:

You can use HTML to format messages in a custom template. The following tags and attributes are allowed in templates:

https://docs.databricks.com/en/sql/user/alerts/index.html

Tags: <a>, <abbr>, <acronym>, <b>, <blockquote>, <body>, <br>, <code>, <div>, <em>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <head>, <hr>, <html>, <i>, <li>, <ol>, <p>, <span>, <strong>, <table>, <tbody>, <td>, <th>, <tr>, <ul>

 

Attributes: href (for <a>), title (for <a>, <abbr>, <acronym>)

VKe
New Contributor III

Hi @szymon_dybczak!

Thank you for your response!

I had seen the list of supported HTML tags in the documentation, but I couldnā€™t believe that it wouldnā€™t be possible to format an email neatly. I was hoping that there might still be a way to achieve a cleaner, more styled layout for the alert notifications.

 

Itā€™s a bit surprising that weā€™re so limited in formatting options, but I appreciate your clarification.

Thanks again for the help!

Hi @VKe ,

No problem. I had the same requirement and I must admit I was also surprised that only a subset of attributes and tags are currently supported.

dec1mo
New Contributor II

Hi @VKe , @szymon_dybczak ,

{{#QUERY_RESULT_ROWS}} and {{/QUERY_RESULT_ROWS}} used to work like a charm in presenting query result in custom alert email, but now the results are showing up blank in my alert notifications. Are you experiencing the same?

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonā€™t want to miss the chance to attend and share knowledge.

If there isnā€™t a group near you, start one and help create a community that brings people together.

Request a New Group