Skip to content

Instantly share code, notes, and snippets.

@Avotrix
Created January 10, 2019 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Avotrix/0fd3d7a476331f9ca1338692f1a68d7d to your computer and use it in GitHub Desktop.
Save Avotrix/0fd3d7a476331f9ca1338692f1a68d7d to your computer and use it in GitHub Desktop.
JS for Custom icon in tables
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());
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment