<?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 How to add colored buttons in a table? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-add-colored-buttons-in-a-table/m-p/628859#M51581</link>
    <description>&lt;P&gt;I added 2 buttons (Delete + Update) to each row in a table. I used the example Script from from&amp;nbsp;&lt;A href="https://community.splunk.com/t5/Splunk-Search/How-do-you-add-buttons-on-table-view/m-p/384712" target="_blank" rel="noopener"&gt;https://community.splunk.com/t5/Splunk-Search/How-do-you-add-buttons-on-table-view/m-p/384712&lt;/A&gt;&amp;nbsp;-&amp;gt;&amp;nbsp;&lt;SPAN&gt;table_with_buttons.js.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In general all is working fine, the most time. But sometimes when I do a Browser Reload the Javascript is not running and the buttons are not colored. If I'm using one of the dropdowns and select an item, the buttons are colored immediately.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It should be looking like this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="swaro_ck_0-1675096008363.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23608i4E2C42552E9D45B4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="swaro_ck_0-1675096008363.png" alt="swaro_ck_0-1675096008363.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I&amp;nbsp; adapted the script a little bit and I ran always a https.//host/en-US/_bump after each change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;require([
  'underscore',
  'jquery',
  'splunkjs/mvc',
  'splunkjs/mvc/tableview',
  'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {

  var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
          canRender: function(cell) {
                  //console.log("Enable this custom cell renderer for field");
                  return _(["Update","Delete"]).contains(cell.field);
          },
          render: function($td, cell) {
                 //console.log("Add a class to the cell based on the returned value");
                  var strCellValue = cell.value;

                  if (cell.field === "Update") {
                          var strHtmlInput="&amp;lt;input type='button' style='background-color:DodgerBlue' class='table-button btn-primary' value='"+strCellValue+"'&amp;gt;&amp;lt;/input&amp;gt;";
                  } else if (cell.field === "Delete") {
                          var strHtmlInput="&amp;lt;input type='button' style='background-color:OrangeRed' class='table-button btn-primary' value='"+strCellValue+"'&amp;gt;&amp;lt;/input&amp;gt;";
                  }
                 $td.append(strHtmlInput);
          }
  });

  mvc.Components.get('taskCollectionTable').getVisualization(function(tableView) {
          // Add custom cell renderer, the table will re-render automatically.
          tableView.table.addCellRenderer(new CustomRangeRenderer());
          tableView.table.render();
  });
});&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And this part in the dashboard:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;  &amp;lt;row depends="$alwaysHideCSSPanel$"&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
        &amp;lt;style&amp;gt;
          #taskCollectionTable table tbody tr td{
            cursor: default !important;
          }
          #taskCollectionTable table tbody tr td input.table-button{
            width: 83px !important;
            position: relative;
            left: 5%;
          }
        &amp;lt;/style&amp;gt;
      &amp;lt;/html&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;  &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I'm missing or doing wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Thanks&lt;/P&gt;</description>
    <pubDate>Mon, 30 Jan 2023 16:42:18 GMT</pubDate>
    <dc:creator>swaro_ck</dc:creator>
    <dc:date>2023-01-30T16:42:18Z</dc:date>
    <item>
      <title>How to add colored buttons in a table?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-add-colored-buttons-in-a-table/m-p/628859#M51581</link>
      <description>&lt;P&gt;I added 2 buttons (Delete + Update) to each row in a table. I used the example Script from from&amp;nbsp;&lt;A href="https://community.splunk.com/t5/Splunk-Search/How-do-you-add-buttons-on-table-view/m-p/384712" target="_blank" rel="noopener"&gt;https://community.splunk.com/t5/Splunk-Search/How-do-you-add-buttons-on-table-view/m-p/384712&lt;/A&gt;&amp;nbsp;-&amp;gt;&amp;nbsp;&lt;SPAN&gt;table_with_buttons.js.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In general all is working fine, the most time. But sometimes when I do a Browser Reload the Javascript is not running and the buttons are not colored. If I'm using one of the dropdowns and select an item, the buttons are colored immediately.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It should be looking like this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="swaro_ck_0-1675096008363.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23608i4E2C42552E9D45B4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="swaro_ck_0-1675096008363.png" alt="swaro_ck_0-1675096008363.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I&amp;nbsp; adapted the script a little bit and I ran always a https.//host/en-US/_bump after each change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;require([
  'underscore',
  'jquery',
  'splunkjs/mvc',
  'splunkjs/mvc/tableview',
  'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {

  var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
          canRender: function(cell) {
                  //console.log("Enable this custom cell renderer for field");
                  return _(["Update","Delete"]).contains(cell.field);
          },
          render: function($td, cell) {
                 //console.log("Add a class to the cell based on the returned value");
                  var strCellValue = cell.value;

                  if (cell.field === "Update") {
                          var strHtmlInput="&amp;lt;input type='button' style='background-color:DodgerBlue' class='table-button btn-primary' value='"+strCellValue+"'&amp;gt;&amp;lt;/input&amp;gt;";
                  } else if (cell.field === "Delete") {
                          var strHtmlInput="&amp;lt;input type='button' style='background-color:OrangeRed' class='table-button btn-primary' value='"+strCellValue+"'&amp;gt;&amp;lt;/input&amp;gt;";
                  }
                 $td.append(strHtmlInput);
          }
  });

  mvc.Components.get('taskCollectionTable').getVisualization(function(tableView) {
          // Add custom cell renderer, the table will re-render automatically.
          tableView.table.addCellRenderer(new CustomRangeRenderer());
          tableView.table.render();
  });
});&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And this part in the dashboard:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;  &amp;lt;row depends="$alwaysHideCSSPanel$"&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
        &amp;lt;style&amp;gt;
          #taskCollectionTable table tbody tr td{
            cursor: default !important;
          }
          #taskCollectionTable table tbody tr td input.table-button{
            width: 83px !important;
            position: relative;
            left: 5%;
          }
        &amp;lt;/style&amp;gt;
      &amp;lt;/html&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;  &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I'm missing or doing wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 16:42:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-add-colored-buttons-in-a-table/m-p/628859#M51581</guid>
      <dc:creator>swaro_ck</dc:creator>
      <dc:date>2023-01-30T16:42:18Z</dc:date>
    </item>
  </channel>
</rss>

