<?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 color depending on value using javascript with a twist, table column names are not fixed? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-color-depending-on-value-using-javascript-with-a/m-p/461551#M130183</link>
    <description>&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I had no idea if it would work!&lt;/P&gt;</description>
    <pubDate>Fri, 18 Oct 2019 21:44:59 GMT</pubDate>
    <dc:creator>jacobpevans</dc:creator>
    <dc:date>2019-10-18T21:44:59Z</dc:date>
    <item>
      <title>How to change color depending on value using javascript with a twist, table column names are not fixed?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-color-depending-on-value-using-javascript-with-a/m-p/461547#M130179</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;

&lt;P&gt;I have below javascript code that I use to change the color of my table cell:&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 _(['Performance']).contains(cell.field);
          },
          render: function($td, cell) {
              var label = cell.value.split("|")[0];
              var val = cell.value.split("|")[1];

                if(val=="high")
                {
                  $td.html("&amp;lt;div class='css_for_high'&amp;gt;"+label+"&amp;lt;/div&amp;gt;")
                } 
                else if(val=="low") 
                {
                  $td.html("&amp;lt;div class='css_for_low'&amp;gt;"+label+"&amp;lt;/div&amp;gt;")
                }
                else if(val=="no")
                {
                  $td.html("&amp;lt;div class='css_for_no'&amp;gt;"+label+"&amp;lt;/div&amp;gt;")
                } 
                else 
                {
                  $td.html("&amp;lt;div class='align_right'&amp;gt;"+label+"&amp;lt;/div&amp;gt;")
                }

          }
      });

      //List of table IDs to add icon
      var tableIDs = ["customTable"];
      for (i=0;i&amp;lt;tableIDs.length;i++) {
          var sh = mvc.Components.get(tableIDs[i]);
          if(typeof(sh)!="undefined") {
              sh.getVisualization(function(tableView) {
                  // Add custom cell renderer and force re-render
                  tableView.table.addCellRenderer(new CustomRangeRenderer());
                  tableView.table.render();
              });
          }
      }    
  });   
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My table has a column "Performance" with samples values like, "99.75|high", "100.00|low", etc.&lt;/P&gt;

&lt;P&gt;What the code does is get these values of column "Performance", split it, and then change the color depending on val. &lt;/P&gt;

&lt;P&gt;Now, I have a table that looks something like this:&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/7832i89D3CB237D3F3015/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;The number of columns increases or decreases depending on the time picker chosen by the user.&lt;BR /&gt;
What should I put in line:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;return _(['Performance']).contains(cell.field);
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to make all the column with date headers be read by the javascript code?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 12:50:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-color-depending-on-value-using-javascript-with-a/m-p/461547#M130179</guid>
      <dc:creator>dojiepreji</dc:creator>
      <dc:date>2019-10-16T12:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to change color depending on value using javascript with a twist, table column names are not fixed?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-color-depending-on-value-using-javascript-with-a/m-p/461548#M130180</link>
      <description>&lt;P&gt;Just guessing, but try changing &lt;CODE&gt;return _(['Performance']).contains(cell.field);&lt;/CODE&gt; to &lt;CODE&gt;return true;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 14:01:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-color-depending-on-value-using-javascript-with-a/m-p/461548#M130180</guid>
      <dc:creator>jacobpevans</dc:creator>
      <dc:date>2019-10-16T14:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to change color depending on value using javascript with a twist, table column names are not fixed?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-color-depending-on-value-using-javascript-with-a/m-p/461549#M130181</link>
      <description>&lt;P&gt;Answered by @jacobevans, change line &lt;CODE&gt;return _(['Performance']).contains(cell.field);&lt;/CODE&gt; to &lt;CODE&gt;return true;&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 11:28:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-color-depending-on-value-using-javascript-with-a/m-p/461549#M130181</guid>
      <dc:creator>dojiepreji</dc:creator>
      <dc:date>2019-10-18T11:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to change color depending on value using javascript with a twist, table column names are not fixed?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-color-depending-on-value-using-javascript-with-a/m-p/461550#M130182</link>
      <description>&lt;P&gt;@dojiepreji  You should accept @jacobevans 's  answer. I have converted his comment to answer.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 12:17:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-color-depending-on-value-using-javascript-with-a/m-p/461550#M130182</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-10-18T12:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to change color depending on value using javascript with a twist, table column names are not fixed?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-color-depending-on-value-using-javascript-with-a/m-p/461551#M130183</link>
      <description>&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I had no idea if it would work!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 21:44:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-color-depending-on-value-using-javascript-with-a/m-p/461551#M130183</guid>
      <dc:creator>jacobpevans</dc:creator>
      <dc:date>2019-10-18T21:44:59Z</dc:date>
    </item>
  </channel>
</rss>

