require([ | |
'underscore', | |
'jquery', | |
'splunkjs/mvc', | |
'splunkjs/mvc/tableview', | |
'splunkjs/mvc/simplexml/ready!' | |
], function(_, $, mvc, TableView) { | |
var CustomIconRenderer = TableView.BaseCellRenderer.extend({ | |
canRender: function(cell) { | |
return cell.field === 'count'; | |
}, | |
render: function($td, cell) { | |
var count = cell.value; | |
// Compute the icon base on the field value | |
var icon; | |
if(count > 3000) { | |
icon = 'alert-circle'; | |
} else if(count > 1000) { | |
icon = 'alert'; | |
} else { | |
icon = 'check'; | |
} | |
// Create the icon element and add it to the table cell | |
$td.addClass('icon-inline numeric').html(_.template('<%- text %> <i class="icon-<%-icon%>"></i>', { | |
icon: icon, | |
text: cell.value | |
})); | |
} | |
}); | |
mvc.Components.get('table1').getVisualization(function(tableView){ | |
// Register custom cell renderer, the table will re-render automatically | |
tableView.addCellRenderer(new CustomIconRenderer()); | |
}); | |
}); |
/*Custom Icons*/ | |
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: orangered; | |
} | |
td.icon .low { | |
color: #006400; | |
} | |
/* Row Coloring */ | |
#highlight tr td { | |
background-color: #c1ffc3 !important; | |
} | |
#highlight tr.range-elevated td { | |
background-color: #ffc57a !important; | |
} | |
#highlight tr.range-severe td { | |
background-color: #d59392 !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;} |
<dashboard script="table_icons_inline.js" stylesheet="table_decorations.css"> | |
<label>Table Icon Set (Inline)</label> | |
<description>Add icons to table cells based on custom conditions.</description> | |
<row> | |
<table id="table1"> |
7. Once all preceding settings are done, click on Save and restart Splunk to make the changes effective.
8. Once Splunk is restarted, the range field will have icons in place of values.
Hence you have successfully Customized and icon in the table.
If you are still facing issue regarding custom icons in dashboards Feel free to Ask Doubts in the Comment Box Below and Don’t Forget to Follow us on 👍 Social Networks, happy Splunking >😉