<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to change cell colors in a dashboard table based on the value? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287847#M87132</link>
    <description>&lt;P&gt;I can see you are adding  css class (eg: range-severe) . Hope you have app.css in correct location?&lt;/P&gt;</description>
    <pubDate>Mon, 26 Oct 2015 11:23:10 GMT</pubDate>
    <dc:creator>koshyk</dc:creator>
    <dc:date>2015-10-26T11:23:10Z</dc:date>
    <item>
      <title>How to change cell colors in a dashboard table based on the value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287846#M87131</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I'm trying to build a dashboard using Splunk 6.2 and I've hit a snag. I want to color a cell in a table depending on the value (numeric and non-numeric).&lt;/P&gt;

&lt;P&gt;I've tried multiple answers provided in this forum as well as the dashboard example app, but haven't been able to make anything work.&lt;/P&gt;

&lt;P&gt;The following is my dashboard xml&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard script="app.js" stylesheet="app.css"&amp;gt;
  &amp;lt;label&amp;gt;Check_Dashboard&amp;lt;/label&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;searchString&amp;gt;index=eventm* sourcetype=healthcheck | head 3 | table CellName,PrimaryRunning,PrimaryStatus,PrimaryEvents,PrimaryData,PrimaryPolicy,SecondaryRunning,SecondaryStatus,SecondaryEvents,SecondaryData,SecondaryPolicy&amp;lt;/searchString&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;table id="health"&amp;gt;
        &amp;lt;searchString&amp;gt;index=eventm* sourcetype=healthcheck | head 3 | fields CellName,PrimaryRunning,PrimaryStatus,PrimaryEvents,PrimaryData,PrimaryPolicy,SecondaryRunning,SecondaryStatus,SecondaryEvents,SecondaryData,SecondaryPolicy |stats by CellName,PrimaryRunning,PrimaryStatus,PrimaryEvents,PrimaryData,PrimaryPolicy,SecondaryRunning,SecondaryStatus,SecondaryEvents,SecondaryData,SecondaryPolicy&amp;lt;/searchString&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And this is my app.js file modified a bit from the examples (I'm not well versed in javascripting):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
'underscore',
'jquery',
'splunkjs/mvc',
'splunkjs/mvc/tableview',
'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {
// Row Coloring Example with custom, client-side range interpretation
var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
canRender: function(cell) {
// Enable this custom cell renderer for both the active_hist_searches and the active_realtime_searches field
return _(['PrimaryRunning']).contains(cell.field);
},
render: function($td, cell) {
// Add a class to the cell based on the returned value
var value = parseFloat(cell.value);
// Apply interpretation for number of historical searches
if (cell.field === 'PrimaryRunning') {
if (value == YES ) {
$td.addClass('range-cell').addClass('range-severe');
}
else if (value == NO ) {
$td.addClass('range-cell').addClass('range-low');
}
}
// Apply interpretation for number of realtime searches
//if (cell.field === 'active_realtime_searches') {
/* if (value &amp;gt; 1) {
$td.addClass('range-cell').addClass('range-severe');
}
 */}
// Update the cell content
$td.text(value.toFixed(2)).addClass('numeric');
}
});
mvc.Components.get('health').getVisualization(function(tableView) {
// Add custom cell renderer, the table will re-render automatically.
tableView.addCellRenderer(new CustomRangeRenderer());
});
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've tried restarting after changing the app.js and app.css files. Nothing seems to be working.&lt;/P&gt;

&lt;P&gt;Any help is much appreciated.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;

&lt;P&gt;EDIT: &lt;/P&gt;

&lt;P&gt;Here is the app.css file:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#highlight td.range-low {
    color: #C0D9D9 !important;
}

#highlight td.range-elevated {
    background-color: #ffc57a !important;
    font-weight: bold;
}

#highlight td.range-severe {
    background-color: #d59392 !important;
    font-weight: bold;
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Oct 2015 06:45:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287846#M87131</guid>
      <dc:creator>kpsg25690</dc:creator>
      <dc:date>2015-10-26T06:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to change cell colors in a dashboard table based on the value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287847#M87132</link>
      <description>&lt;P&gt;I can see you are adding  css class (eg: range-severe) . Hope you have app.css in correct location?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2015 11:23:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287847#M87132</guid>
      <dc:creator>koshyk</dc:creator>
      <dc:date>2015-10-26T11:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to change cell colors in a dashboard table based on the value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287848#M87133</link>
      <description>&lt;P&gt;This is not a complete answer but an idea to get you to an answer.  Splunk has always supported the concept of &lt;CODE&gt;heat maps&lt;/CODE&gt; which are implemented using the feature that you need.  If you can figure out how splunk does &lt;CODE&gt;heat-mapping&lt;/CODE&gt;, you should be able to copy it.  Here are some places to start:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.0/Viz/Visualizationreference"&gt;http://docs.splunk.com/Documentation/Splunk/6.3.0/Viz/Visualizationreference&lt;/A&gt;&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/132524/custom-heatmap-logic-in-advanced-xml.html"&gt;https://answers.splunk.com/answers/132524/custom-heatmap-logic-in-advanced-xml.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2015 15:49:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287848#M87133</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-26T15:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to change cell colors in a dashboard table based on the value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287849#M87134</link>
      <description>&lt;P&gt;I'm assuming based on the JS that the values for the 'PrimaryRunning' field are either the string YES or NO, so your if statements need to be like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if (value === 'YES' ) {
 $td.addClass('range-cell').addClass('range-severe');
 }
 else if (value === 'NO' ) {
 $td.addClass('range-cell').addClass('range-low');
 }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also, post your CSS if this doesn't help...that needs to match up too.&lt;/P&gt;

&lt;P&gt;Update:&lt;BR /&gt;
Your CSS selector names need to match the id:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#health td.range-low {
     color: #C0D9D9 !important;
 }

 #health td.range-elevated {
     background-color: #ffc57a !important;
     font-weight: bold;
 }

 #health td.range-severe {
     background-color: #d59392 !important;
     font-weight: bold;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Oct 2015 17:18:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287849#M87134</guid>
      <dc:creator>stmyers7941</dc:creator>
      <dc:date>2015-10-26T17:18:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to change cell colors in a dashboard table based on the value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287850#M87135</link>
      <description>&lt;P&gt;Yes, your assumption is correct, the values in that field is YES or NO, but I have also tried this with other numeric fields to see if it's working or not and it's not.&lt;/P&gt;

&lt;P&gt;I also tried using the format you suggested to no result.&lt;/P&gt;

&lt;P&gt;I have updated the app.css in the original post for your reference.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2015 06:51:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287850#M87135</guid>
      <dc:creator>kpsg25690</dc:creator>
      <dc:date>2015-10-27T06:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to change cell colors in a dashboard table based on the value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287851#M87136</link>
      <description>&lt;P&gt;I have the css in the appserver/static folder of the app. I have also added the css for reference.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2015 06:52:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287851#M87136</guid>
      <dc:creator>kpsg25690</dc:creator>
      <dc:date>2015-10-27T06:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to change cell colors in a dashboard table based on the value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287852#M87137</link>
      <description>&lt;P&gt;See updates in my answer - you need to adjust you CSS.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2015 13:00:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287852#M87137</guid>
      <dc:creator>stmyers7941</dc:creator>
      <dc:date>2015-10-27T13:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to change cell colors in a dashboard table based on the value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287853#M87138</link>
      <description>&lt;P&gt;Still isn't working. Although I think it's not a problem with the CSS but with the javascript itself, I looked at the output in the console window and I couldn't see the class that was added to the field. However in the example app I can see the class.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 07:20:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287853#M87138</guid>
      <dc:creator>kpsg25690</dc:creator>
      <dc:date>2015-10-29T07:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to change cell colors in a dashboard table based on the value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287854#M87139</link>
      <description>&lt;P&gt;I'd start from testing if this function goes in to first and second if.&lt;BR /&gt;
So please try something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if (cell.field === 'PrimaryRunning') {
   console.log('found primaryrunning cell');
  if (cell.value === 'YES') {
    console.log('value = yes, adding class');
  }
  else if (cell.value === 'NO') {
    console.log('value = no, adding class);
  }
  else {
    console.log('value = ' + cell.value);
  }
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Btw i've noticed that there was value = parseFloat(cell.value) in Your code, and then You are comparing this float against strings 'YES' / 'NO'? This will always evaluate to false.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 08:29:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287854#M87139</guid>
      <dc:creator>piUek</dc:creator>
      <dc:date>2015-10-29T08:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to change cell colors in a dashboard table based on the value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287855#M87140</link>
      <description>&lt;P&gt;Got It working!! Thanks everybody!&lt;/P&gt;

&lt;P&gt;Somehow the javascript was not getting triggered, I cleared the browser cache and everything and also restarted the splunk services and something starting working after that I just tweaked the script a bit to suit my needs.&lt;/P&gt;

&lt;P&gt;@piUek I did know about that float value, I had changed it already to process a string but the problem was I couldn't see the script reaching that point and the console logging helped in that. &lt;/P&gt;

&lt;P&gt;Thanks piUek and stymers7941!&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 10:02:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287855#M87140</guid>
      <dc:creator>kpsg25690</dc:creator>
      <dc:date>2015-10-29T10:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to change cell colors in a dashboard table based on the value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287856#M87141</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Is it possible to do the same for string values in fields instead of numeric.&lt;/P&gt;

&lt;P&gt;Am trying this but not working any help provided is appreciated.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if (cell.field !== "source_subnet") {
                 if (value !== "100%") {
                     $td.addClass("range-cell").addClass("range-severe");
                 }
                 // Update the cell content
                 $td.text(value).addClass('string');
             }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please ignore am using "100%" as string.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 27 Apr 2020 06:22:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-cell-colors-in-a-dashboard-table-based-on-the/m-p/287856#M87141</guid>
      <dc:creator>PowerPacked</dc:creator>
      <dc:date>2020-04-27T06:22:12Z</dc:date>
    </item>
  </channel>
</rss>

