question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add simple javascript for conditional formatting of cells in Table Chart

See original GitHub issue

Feature Request:

I believe there is much demand for a KPI monitoring chart type such as a gauge or other forms of KPI Visualization Types.

Due to lack of these kind of charts I believe it must be possible to add a small piece of javascript to conditionally format cells in a table.

I added the following piece of code to templates/superset/partials/asset_bundle.html Is this the right way? Templates/superset/partials/asset_bundle.html

{% macro js_bundle(filename) %}
  {# HTML comment is needed for webpack-dev-server to replace assets
     with development version #}
  <!-- Bundle js {{ filename }} START -->
  {% for entry in js_manifest(filename) %}
    <script src="{{ entry }}"></script>
    <script src="override.js"></script>  |<<<<<<<<<<<<<<<
  {% endfor %}
  <!-- Bundle js {{ filename }} END -->
{% endmacro %}
{% macro css_bundle(filename) %}
  <!-- Bundle css {{ filename }} START -->
  {% for entry in css_manifest(filename) %}
    <link rel="stylesheet" type="text/css" href="{{ entry }}" />
  {% endfor %}
  <!-- Bundle css {{ filename }} END -->
{% endmacro `%}

Override.js

var table = document.getElementById("DataTables_Table_0");
var tbody = document.getElementsByTagName("tbody")[0];
var cells = document.getElementsByTagName("td");

for (var i=0, len=cells.length; i<len; i++){
    if (parseInt(cells[i].innerHTML,10) > 5){
        cells[i].className = 'red';
    }
    else if (parseInt(cells[i].innerHTML,10) < -5){
        cells[i].className = 'green';
    }
}

Where should I place this override.js and lateron the css files? Is this a valid way of adding a simple js to have some kind of conditional formatting?

Any suggestions or help is appreciated

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
magentomaniaccommented, Jul 30, 2020

I believe I finally found a way to run arbitrary Javascript using the markdown element. Couldn’t get this to work using any official methods including markup chart visualization - which simply refuses to be added to dashboards.

On your dashboard click “edit dashboard” and drag&drop the mardown element anywhere. Click on it on edit. Paste the following markdown to run a small piece of arbitrary javascript and confirm it’s possible to get it working:

<p>Chart title</p>
<img src=";" onerror="alert(0);" />

Since this format is limited by wrapping in double-quotes it’s best to attach your javascript from an external source, like so: Screen Shot 2020-07-30 at 17 07 06

It’s a hack (literally abusing a XSS attack vector) but it’s the only way I could find that works. Hope this helps.

1reaction
kalimuthu123commented, May 7, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Add simple javascript for conditional formatting of cells in ...
Due to lack of these kind of charts I believe it must be possible to add a small piece of javascript to conditionally...
Read more >
Conditional formatting html table with javascript - Stack Overflow
For a pure JS solution to this (negating the fact that you had tried to implement a jQuery solution), just use the following:...
Read more >
Conditional Formatting in JavaScript (ES5) Pivot Table control
Allows end user to change the appearance of the pivot table value cells with its background color, font color, font family, and font...
Read more >
Apply conditional formatting to Excel ranges - Microsoft Learn
The Excel JavaScript Library provides APIs to apply conditional formatting to data ranges in your worksheets. This functionality makes large ...
Read more >
Table With Conditional Formats and Data Validation - GrapeCity
Table's columns B:F have data validation rules. Column F also has conditional formatting rules. Click in cell F11 (value '13') and press the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found