Archive

Colouring Table cells based on the table ID and Cell Value

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

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

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

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

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
State of Splunk Careers

Access the Splunk Careers Report to see real data that shows how Splunk mastery increases your value and job satisfaction.

Find out what your skills are worth!