Created
January 10, 2019 19:21
-
-
Save Avotrix/0fd3d7a476331f9ca1338692f1a68d7d to your computer and use it in GitHub Desktop.
JS for Custom icon in tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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