Dashboards & Visualizations

Colouring Table cells based on the table ID and Cell Value

ahallak2016
Explorer

Hi all,

I would like to color table cells based on the table ID and the cell values. The only examples that I have found on splunk answers involve checking what the cell.field is first before checking the values, but in my case this wont be possible because the field names returned may be different with each search. Furthermore, different tables will have the exact same field names but will always have different coloring rules (thresholds).

Is there a way to color the table cells by first checking what the table ID is and then checking the values?

This is what I would like to do (notice how i would like to check what the table id is in the if statement, instead of checking what the cell.field is?):

var val = cell.value;
var split_val = val.split("%")[0];
var value = parseFloat(split_val); 

if ({table id} == 'some value') 
{
      if (value >= 50.0) 
     {
       $td.addClass('Green');
     }
     else
     {
        $td.addClass('Red');
     }
}
if ({table id} == 'another value') 
{
      if (value >= 70.0) 
     {
       $td.addClass('Green');
     }
     else
     {
        $td.addClass('Red');
     }
}
Tags (1)
0 Karma
1 Solution

rjthibod
Champion

I am pretty sure the answer is no, you cannot do what you ask.

My understanding is the coding pattern dictates that you must add a cell rendering callback (via addCellRenderer()) for the table instance, but the callback function does not get the table ID when it is called. So you can create multiple callback functions (i.e., a unique callback for each table), and then apply your thresholds accordingly.

View solution in original post

niketn
Legend

If you upgrade to 6.5 or higher you will have cell coloring option built in to the table. Without JS/CSS extension.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

rjthibod
Champion

I am pretty sure the answer is no, you cannot do what you ask.

My understanding is the coding pattern dictates that you must add a cell rendering callback (via addCellRenderer()) for the table instance, but the callback function does not get the table ID when it is called. So you can create multiple callback functions (i.e., a unique callback for each table), and then apply your thresholds accordingly.

ahallak2016
Explorer

Ahh thanks for the reply.

I eventually found a work around by creating a separate JS file for each table. Its not a very elegant solutions but it will suffice for the time being.

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...