You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "FrancescoCastaldi (via GitHub)" <gi...@apache.org> on 2026/10/24 13:38:06 UTC
Re: [D] render as html [superset]
GitHub user FrancescoCastaldi added a comment to the discussion: render as html
This happens because **"Render as HTML"** in the Table chart is strictly a client-side frontend display feature.
### Why the HTML tags appear in exports
When you click **Download CSV** or **Download Excel**, Superset does not scrape the rendered browser DOM. Instead, it sends an API request directly to `/api/v1/chart/data` with format `csv` or `xlsx`. The backend database query executes, and the raw SQL result set is exported directly to file. Because your `<span>` tags were generated inside the SQL metric string, the CSV/Excel file receives the raw SQL string.
### How to achieve styled display in the browser and clean exports
#### Solution 1: Use Native Conditional Formatting instead of HTML in SQL (Best Solution)
Instead of embedding `<span>` tags in your Custom SQL, write your metric to return the pure, clean numeric or string value (e.g., `SUM(sales)`).
Then, use Superset's native formatting controls:
1. In the Table chart configuration in Explore, switch to the **Customize** tab.
2. Scroll to the **Conditional Formatting** section.
3. Click **Add color formatting rule**.
4. Configure your visual logic (for example: if value > 100, color green; if value < 0, color red).
**Result:** The browser displays rich color highlights and badges, while CSV and Excel exports download 100% clean numbers without HTML markup.
#### Solution 2: Expose Separate Display and Export Columns
If you require complex HTML that conditional formatting cannot replicate:
1. In your dataset, maintain two columns:
- `metric_raw`: clean numeric or plain text value.
- `metric_html`: contains the formatted `<span ...>...</span>` string.
2. In the Table chart, you can display `metric_html` for online dashboard users, and provide an alternate export-oriented view or use SQL `REPLACE()` / regex stripping in a custom export post-processor.
GitHub link: https://github.com/apache/superset/discussions/40900#discussioncomment-19164797
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org