<?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 color a table row based on a cell's value? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269522#M17063</link>
    <description>&lt;P&gt;This is a great answer because it helped me learn more about coloring rows and using it for multiple tables in a dashboard.&lt;/P&gt;

&lt;P&gt;It wasn't working for me until I found this post:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/318747/can-i-have-hidden-fields-in-a-tableview.html"&gt;https://answers.splunk.com/answers/318747/can-i-have-hidden-fields-in-a-tableview.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I got two tables in the same dashboard working by creating a separate .js file for each table.&lt;BR /&gt;
Instead of having two&lt;BR /&gt;
 mvc.Components.get()&lt;BR /&gt;
in the same .js document I created two .js documents each with a single mvc.Component.get()  named for the appropriate table.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Mar 2017 23:56:46 GMT</pubDate>
    <dc:creator>cpt12tech</dc:creator>
    <dc:date>2017-03-21T23:56:46Z</dc:date>
    <item>
      <title>How to color a table row based on a cell's value?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269514#M17055</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;My search: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="index1" OR index="4" | eval Value=if(index="index1", round(((Value-100)*-1), 0), round(Value, 0)) | where Value&amp;gt;50
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am trying to color the table in red, yellow, and green using the numbers returned from Value. The table has 2 columns -&amp;gt; test1 and test2. Value result will be listed under test2 column and the colors should be: 0-60 green , 60-80 yellow , 80-100 red.&lt;/P&gt;

&lt;P&gt;CSS : &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;td.icon {
    text-align: center;
}

td.icon i {
    font-size: 25px;
    text-shadow: 1px 1px #aaa;
}
td.icon .severe {
    color: red;
}
td.icon .elevated {
    color: orange;
}
td.icon .low {
    color: green;
}
    /* Row Coloring */
#highlight tr td {
    background-color: #c1ffc3 !important;
}

#highlight tr.range-elevated td {
    background-color: orange !important;
}
#highlight tr.range-severe td {
    background-color: red !important;
}
#highlight .table td {
    border-top: 1px solid #fff;
}
#highlight td.range-severe, td.range-elevated {
    font-weight: bold;
}
.icon-inline i {
    font-size: 18px;
    margin-left: 5px;
}
.icon-inline i.icon-alert-circle {
    color: #ef392c;
}
.icon-inline i.icon-alert {
    color: #ff9c1a;
}
.icon-inline i.icon-check {
    color: #5fff5e;
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Script file :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {
    var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
        canRender: function(cell) {
            return _(['test2']).contains(cell.field);
        },
        render: function($td.cell) {
            var value = parseFloat(cell.value)
            if (cell.field === 'test2') {
                    if (value &amp;gt; 80) {
                    $td.addClass('range-cell').addClass('range-severe');
                     }
                }
            }
        }
    });
    mvc.Components.get('highlight').getVisualization(function(tableView) {
        tableView.on('rendered', function() {
            tableView.$el.find('td.range-cell').each(function() {
               $(this).parents('tr').addClass(this.className);
            });
        });
        tableView.addCellRenderer(new CustomRangeRenderer());
    });
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The result i get is all table rows in green, regardles of the value. Please help and thank you in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2016 16:22:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269514#M17055</guid>
      <dc:creator>andrei1bc</dc:creator>
      <dc:date>2016-02-04T16:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to color a table row based on a cell's value?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269515#M17056</link>
      <description>&lt;P&gt;hi andrei1bc,&lt;/P&gt;

&lt;P&gt;that is the value for the file that use for do  the test:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;name     test1    test2
a          12       25
b           2        2
c           3        61
d         12       75
e           3       81
f            8       90
g          5       50
h         1       95
i          3       70
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;next try like this:&lt;/P&gt;

&lt;P&gt;table_row_highlighting.xml&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard script="table.js" stylesheet="table.css"&amp;gt;
    &amp;lt;label&amp;gt;Table Row Highlighting&amp;lt;/label&amp;gt;

    &amp;lt;row&amp;gt;
        &amp;lt;table id="highlight"&amp;gt;
            &amp;lt;title&amp;gt;Row Coloring&amp;lt;/title&amp;gt;
            &amp;lt;searchString&amp;gt;index=test |table name test1 test2&amp;lt;/searchString&amp;gt;
            &amp;lt;earliestTime&amp;gt;0&amp;lt;/earliestTime&amp;gt;
            &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;/table&amp;gt;
    &amp;lt;/row&amp;gt;

&amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;table.js&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 _(['test2']).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 === 'test2') {
                if (value &amp;lt; 60) {
                    $td.addClass('range-cell').addClass('range-elevated');
                }
                else if(value &amp;gt; 60 &amp;amp;&amp;amp; value &amp;lt; 80) {
                    $td.addClass('range-cell').addClass('range-severe');
                }
                else if(value &amp;gt; 80 &amp;amp;&amp;amp; value &amp;lt; 100) {
                    $td.addClass('range-cell').addClass('range-higher');
                }

            }

            // Update the cell content
            $td.text(value.toFixed(2)).addClass('numeric');
        }
    });

    mvc.Components.get('highlight').getVisualization(function(tableView) {
        tableView.on('rendered', function() {
            // Apply class of the cells to the parent row in order to color the whole row
            tableView.$el.find('td.range-cell').each(function() {
                $(this).parents('tr').addClass(this.className);
            });
        });
        // Add custom cell renderer, the table will re-render automatically.
        tableView.addCellRenderer(new CustomRangeRenderer());
    });

});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;table.css&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;/* Row Coloring */
#highlight tr.range-elevated td {
    background-color: #329606 !important;               
}

#highlight tr.range-severe td {
    background-color: #F1FF70 !important;              
}

#highlight tr.range-higher td {
    background-color: #D6344D !important;              
}

#highlight td.range-severe, td.range-elevated, td.range-higher{
    font-weight: 800;
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;don't forget to restart splunkd&lt;BR /&gt;
after restart, the result is this:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/101173-capture.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;let know if it's work&lt;/P&gt;

&lt;P&gt;please forgive my english&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:40:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269515#M17056</guid>
      <dc:creator>gyslainlatsa</dc:creator>
      <dc:date>2020-09-29T08:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to color a table row based on a cell's value?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269516#M17057</link>
      <description>&lt;P&gt;Thank you for the clear post. But the CSS does not seem to update if modified (just the color code) and restarting splunk does not fix it . Any suggestions ?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 12:28:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269516#M17057</guid>
      <dc:creator>andrei1bc</dc:creator>
      <dc:date>2016-02-08T12:28:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to color a table row based on a cell's value?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269517#M17058</link>
      <description>&lt;P&gt;Make sure you clean your browser's cache for the page, e.g. STRG-F5 (depends on your browser).&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 12:33:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269517#M17058</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2016-02-08T12:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to color a table row based on a cell's value?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269518#M17059</link>
      <description>&lt;P&gt;hi andrei1bc,&lt;/P&gt;

&lt;P&gt;I had the same problem when I was looking for the solution. trying to empty the cache of your browser&lt;/P&gt;

&lt;P&gt;if it works, do not forget to vote and accept my answer.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 12:38:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269518#M17059</guid>
      <dc:creator>gyslainlatsa</dc:creator>
      <dc:date>2016-02-08T12:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to color a table row based on a cell's value?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269519#M17060</link>
      <description>&lt;P&gt;gyslainlatsa your solution worked. Thank you. &lt;/P&gt;

&lt;P&gt;As far as it goes with the CSS update issue, it was not related to the browser cache but to the fact that i was using the script in 3 tables instead of 1. So i added this to the script :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; mvc.Components.get('highlight_table1').getVisualization(function(tableView) {
     tableView.on('rendered', function() {
         // Apply class of the cells to the parent row in order to color the whole row
         tableView.$el.find('td.range-cell').each(function() {
             $(this).parents('tr').addClass(this.className);
         });
     });

 mvc.Components.get('highlight_table2').getVisualization(function(tableView) {
     tableView.on('rendered', function() {
         // Apply class of the cells to the parent row in order to color the whole row
         tableView.$el.find('td.range-cell').each(function() {
             $(this).parents('tr').addClass(this.className);
         });
     });

 mvc.Components.get('highlight_tabel3').getVisualization(function(tableView) {
     tableView.on('rendered', function() {
         // Apply class of the cells to the parent row in order to color the whole row
         tableView.$el.find('td.range-cell').each(function() {
             $(this).parents('tr').addClass(this.className);
         });
     });
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have also modified the CSS file to reflect the changes, this way i can use individual colors in each table.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;/* Row Coloring */
#highlight_table1 tr.range-elevated td {
    background-color: #329606 !important;                  
}

#highlight_table1 tr.range-severe td {
    background-color: #F1FF70 !important;               
}

#highlight_table1 tr.range-higher td {
    background-color: #D6344D !important;               
}

#highlight_table1 td.range-severe, td.range-elevated, td.range-higher{
    font-weight: 800;
}

#highlight_table2 tr.range-elevated td {
    background-color: #329606 !important;                  
}

#highlight_table2 tr.range-severe td {
    background-color: #F1FF70 !important;               
}

#highlight_table2 tr.range-higher td {
    background-color: #D6344D !important;               
}

#highlight_table2 td.range-severe, td.range-elevated, td.range-higher{
    font-weight: 800;
}

#highlight_table3 tr.range-elevated td {
    background-color: #329606 !important;                  
}

#highlight_table3 tr.range-severe td {
    background-color: #F1FF70 !important;               
}

#highlight_table3 tr.range-higher td {
    background-color: #D6344D !important;               
}

#highlight_table3 td.range-severe, td.range-elevated, td.range-higher{
    font-weight: 800;
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Feb 2016 08:55:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269519#M17060</guid>
      <dc:creator>andrei1bc</dc:creator>
      <dc:date>2016-02-09T08:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to color a table row based on a cell's value?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269520#M17061</link>
      <description>&lt;P&gt;thank, I'm happy for you&lt;/P&gt;

&lt;P&gt;please don't forget to vote&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2016 09:06:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269520#M17061</guid>
      <dc:creator>gyslainlatsa</dc:creator>
      <dc:date>2016-02-09T09:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to color a table row based on a cell's value?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269521#M17062</link>
      <description>&lt;P&gt;This was a great answer, mainly because it showed me how to run multiple tables from a .js file and learn more about how to color rows.  &lt;/P&gt;

&lt;P&gt;I was having problems getting a second table to populate in a dashboard using row highlighting.&lt;/P&gt;

&lt;P&gt;Finally found this post here:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/306849/rangemap-cell-formatting-for-multiple-tables.html"&gt;https://answers.splunk.com/answers/306849/rangemap-cell-formatting-for-multiple-tables.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;where someone created two .js files, one for each table.  In this thread it would be three .js files.  And now the .js scripts are correctly formatting the tables.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 21:57:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269521#M17062</guid>
      <dc:creator>cpt12tech</dc:creator>
      <dc:date>2017-03-21T21:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to color a table row based on a cell's value?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269522#M17063</link>
      <description>&lt;P&gt;This is a great answer because it helped me learn more about coloring rows and using it for multiple tables in a dashboard.&lt;/P&gt;

&lt;P&gt;It wasn't working for me until I found this post:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/318747/can-i-have-hidden-fields-in-a-tableview.html"&gt;https://answers.splunk.com/answers/318747/can-i-have-hidden-fields-in-a-tableview.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I got two tables in the same dashboard working by creating a separate .js file for each table.&lt;BR /&gt;
Instead of having two&lt;BR /&gt;
 mvc.Components.get()&lt;BR /&gt;
in the same .js document I created two .js documents each with a single mvc.Component.get()  named for the appropriate table.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 23:56:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269522#M17063</guid>
      <dc:creator>cpt12tech</dc:creator>
      <dc:date>2017-03-21T23:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to color a table row based on a cell's value?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269523#M17064</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:23:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269523#M17064</guid>
      <dc:creator>PowerPacked</dc:creator>
      <dc:date>2020-04-27T06:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to color a table row based on a cell's value?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269524#M17065</link>
      <description>&lt;P&gt;@PowerPacked this is a very old question from 2016 to bump, however you should be able to apply table row coloring based on String values as well. Following is an olde answer of mine: &lt;A href="https://answers.splunk.com/answers/581747/change-row-color-when-the-field-time-value-increas.html"&gt;https://answers.splunk.com/answers/581747/change-row-color-when-the-field-time-value-increas.html&lt;/A&gt;&lt;BR /&gt;
or &lt;A href="https://answers.splunk.com/answers/583047/can-i-color-a-cell-based-on-condition.html"&gt;https://answers.splunk.com/answers/583047/can-i-color-a-cell-based-on-condition.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;You would need to ensure to add a &lt;CODE&gt;setTimeout()&lt;/CODE&gt; function if you are running &lt;CODE&gt;Splunk 6.6 or higher&lt;/CODE&gt;. Refer to another answer: &lt;A href="https://answers.splunk.com/answers/614788/splunk-dashboard-examples-table-row-highlighting-b.html"&gt;https://answers.splunk.com/answers/614788/splunk-dashboard-examples-table-row-highlighting-b.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Finally also wanted to show you purely SimpleXML based approach for table row coloring based on &lt;CODE&gt;expression&lt;/CODE&gt; &lt;CODE&gt;colorPalette&lt;/CODE&gt; format.: &lt;A href="https://answers.splunk.com/answers/820403/how-to-change-font-color-based-on-a-condition-for.html"&gt;https://answers.splunk.com/answers/820403/how-to-change-font-color-based-on-a-condition-for.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Please upvote the respective answer/s if you find them helpful &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Apr 2020 07:18:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-color-a-table-row-based-on-a-cell-s-value/m-p/269524#M17065</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-04-27T07:18:39Z</dc:date>
    </item>
  </channel>
</rss>

