<?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: While trying to color table cells based on values under dynamic columns with JavaScript, why is content no longer showing in the table? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/While-trying-to-color-table-cells-based-on-values-under-dynamic/m-p/172449#M49405</link>
    <description>&lt;P&gt;I would try different approach for getting td position. &lt;BR /&gt;
Since the table is not rendered yet (we are in the setup stage) I'd rather use cell.index.&lt;/P&gt;

&lt;P&gt;So instead of &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var tdPosition = $td.parent().children().index($td[0]);
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var tdPosition = cell.index;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;We can even go further and render custom classes only for the columns which are not first.&lt;BR /&gt;
Then your entire function would be this way:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var CustomCellRenderer = TableView.BaseCellRenderer.extend({
        canRender: function(cell) {
            // Enable this custom cell renderer for all fields except first column
            return cell.index &amp;gt; 0;
        },
        render: function($td, cell) {
            var value = parseFloat(cell.value);
            if ((value &amp;gt; 0) &amp;amp;&amp;amp; (value &amp;lt;= 50)) {
                $td.addClass('range-cell').addClass('range-severe');
            } else if ((value &amp;gt; 50) &amp;amp;&amp;amp; (value &amp;lt;= 100)) {
                $td.addClass('range-cell').addClass('range-elevated');
            } else if ((value &amp;gt; 100) &amp;amp;&amp;amp; (value &amp;lt;= 150)) {
                $td.addClass('range-cell').addClass('range-low');
            } else {
                $td.addClass('range-cell').addClass('range-empty');
            }

            // Update the cell content
            $td.text(value).addClass('numeric');
        }
    });
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 01 Oct 2015 09:42:51 GMT</pubDate>
    <dc:creator>piUek</dc:creator>
    <dc:date>2015-10-01T09:42:51Z</dc:date>
    <item>
      <title>While trying to color table cells based on values under dynamic columns with JavaScript, why is content no longer showing in the table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/While-trying-to-color-table-cells-based-on-values-under-dynamic/m-p/172448#M49404</link>
      <description>&lt;P&gt;Hi Guys.&lt;/P&gt;

&lt;P&gt;I want to color the cells of my table based on the values that belong to columns other than the first column. My column names are Dynamic. Below is a Sample of what my table looks like if we select 'Last 3 days' from timepicker:&lt;/P&gt;

&lt;P&gt;Channel 23-Jun-15 22-Jun-15 21-Jun-15 20-Jun-15&lt;BR /&gt;
BBC Sport 6 3 7 9&lt;BR /&gt;
Discovery 2 6 4 3&lt;/P&gt;

&lt;P&gt;Here i want to color all the cells after "Channel" column based on the cell values.&lt;BR /&gt;
Below is the Script i am using :&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 true;
        },
        render: function($td, cell) {
            // Add a class to the cell based on the returned value
            // Apply interpretation for number of historical searches
                var tdPosition = $td.parent().children().index($td[0]);
                var value = cell.value;
            if (tdPosition &amp;gt; 0) {
                    var value = parseFloat(value);
                if ((value &amp;gt; 0) &amp;amp;&amp;amp; (value &amp;lt;= 50)) {
                    $td.addClass('range-cell').addClass('range-severe');
                }
                else if ((value &amp;gt; 50) &amp;amp;&amp;amp; (value &amp;lt;= 100)) {
                    $td.addClass('range-cell').addClass('range-elevated');
                }
                else if ((value &amp;gt; 100) &amp;amp;&amp;amp; (value &amp;lt;= 150)) {
                    $td.addClass('range-cell').addClass('range-low');
                }
                    else {
                        $td.addClass('range-cell').addClass('range-empty');
                    }

            }
            // Update the cell content
                $td.text(value).addClass('numeric');
        }
    });
    mvc.Components.get('rettable').getVisualization(function(tableView) {
        // Add custom cell renderer
        tableView.table.addCellRenderer(new CustomRangeRenderer());
        // 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).addClass(this.className);
           // });
        //});
        // Force the table to re-render
        tableView.table.render();
    });
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But the table is showing empty i.e. only column names are showing without any values. I think there is some problem with updating cell content in query. Please help.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2015 11:15:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/While-trying-to-color-table-cells-based-on-values-under-dynamic/m-p/172448#M49404</guid>
      <dc:creator>kabiraj</dc:creator>
      <dc:date>2015-06-23T11:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: While trying to color table cells based on values under dynamic columns with JavaScript, why is content no longer showing in the table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/While-trying-to-color-table-cells-based-on-values-under-dynamic/m-p/172449#M49405</link>
      <description>&lt;P&gt;I would try different approach for getting td position. &lt;BR /&gt;
Since the table is not rendered yet (we are in the setup stage) I'd rather use cell.index.&lt;/P&gt;

&lt;P&gt;So instead of &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var tdPosition = $td.parent().children().index($td[0]);
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var tdPosition = cell.index;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;We can even go further and render custom classes only for the columns which are not first.&lt;BR /&gt;
Then your entire function would be this way:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var CustomCellRenderer = TableView.BaseCellRenderer.extend({
        canRender: function(cell) {
            // Enable this custom cell renderer for all fields except first column
            return cell.index &amp;gt; 0;
        },
        render: function($td, cell) {
            var value = parseFloat(cell.value);
            if ((value &amp;gt; 0) &amp;amp;&amp;amp; (value &amp;lt;= 50)) {
                $td.addClass('range-cell').addClass('range-severe');
            } else if ((value &amp;gt; 50) &amp;amp;&amp;amp; (value &amp;lt;= 100)) {
                $td.addClass('range-cell').addClass('range-elevated');
            } else if ((value &amp;gt; 100) &amp;amp;&amp;amp; (value &amp;lt;= 150)) {
                $td.addClass('range-cell').addClass('range-low');
            } else {
                $td.addClass('range-cell').addClass('range-empty');
            }

            // Update the cell content
            $td.text(value).addClass('numeric');
        }
    });
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Oct 2015 09:42:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/While-trying-to-color-table-cells-based-on-values-under-dynamic/m-p/172449#M49405</guid>
      <dc:creator>piUek</dc:creator>
      <dc:date>2015-10-01T09:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: While trying to color table cells based on values under dynamic columns with JavaScript, why is content no longer showing in the table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/While-trying-to-color-table-cells-based-on-values-under-dynamic/m-p/172450#M49406</link>
      <description>&lt;P&gt;Thank You piUek. Appreciate your answer but i got it long back. Thanks again for replying.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2015 06:05:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/While-trying-to-color-table-cells-based-on-values-under-dynamic/m-p/172450#M49406</guid>
      <dc:creator>kabiraj</dc:creator>
      <dc:date>2015-10-05T06:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: While trying to color table cells based on values under dynamic columns with JavaScript, why is content no longer showing in the table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/While-trying-to-color-table-cells-based-on-values-under-dynamic/m-p/172451#M49407</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:20:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/While-trying-to-color-table-cells-based-on-values-under-dynamic/m-p/172451#M49407</guid>
      <dc:creator>PowerPacked</dc:creator>
      <dc:date>2020-04-27T06:20:21Z</dc:date>
    </item>
  </channel>
</rss>

