Dashboards & Visualizations

How to add colored buttons in a table?

swaro_ck
Path Finder

I added 2 buttons (Delete + Update) to each row in a table. I used the example Script from from https://community.splunk.com/t5/Splunk-Search/How-do-you-add-buttons-on-table-view/m-p/384712 -> table_with_buttons.js. 

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.

It should be looking like this:

swaro_ck_0-1675096008363.png

I  adapted the script a little bit and I ran always a https.//host/en-US/_bump after each change.

 

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="<input type='button' style='background-color:DodgerBlue' class='table-button btn-primary' value='"+strCellValue+"'></input>";
                  } else if (cell.field === "Delete") {
                          var strHtmlInput="<input type='button' style='background-color:OrangeRed' class='table-button btn-primary' value='"+strCellValue+"'></input>";
                  }
                 $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();
  });
});

 

 

And this part in the dashboard:

 

  <row depends="$alwaysHideCSSPanel$">
    <panel>
      <html>
        <style>
          #taskCollectionTable table tbody tr td{
            cursor: default !important;
          }
          #taskCollectionTable table tbody tr td input.table-button{
            width: 83px !important;
            position: relative;
            left: 5%;
          }
        </style>
      </html>
    </panel>
  </row>  

 

 

What I'm missing or doing wrong?

 Thanks

Labels (4)
0 Karma
Get Updates on the Splunk Community!

Monitoring Postgres with OpenTelemetry

Behind every business-critical application, you’ll find databases. These behind-the-scenes stores power ...

Mastering Synthetic Browser Testing: Pro Tips to Keep Your Web App Running Smoothly

To start, if you're new to synthetic monitoring, I recommend exploring this synthetic monitoring overview. In ...

Splunk Edge Processor | Popular Use Cases to Get Started with Edge Processor

Splunk Edge Processor offers more efficient, flexible data transformation – helping you reduce noise, control ...