Perhaps there is something that I don't understand. I see from debug output that canRender is called for every column field, which is expected. Per the example from Splunk Dashboard Examples for Table Cell Highlighting, it returns true if the field should be rendered, otherwise false.
My code returns true for any field that is not the testcase field.
However, I had to add code in the render function to update the testcase field value; without this the cell ends up blank. Here is the complete working code:
require([
'underscore',
'jquery',
'splunkjs/mvc',
'splunkjs/mvc/tableview',
'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {
// Row Coloring Example with custom, client-side range interpretation
var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
canRender: function(cell) {
console.log("canRender: cell.field=" + cell.field);
// Enable this custom cell renderer for any field except the test case field
var testpattern = new RegExp ('test', 'i');
return _(!testpattern.test(cell.field));
},
render: function($td, cell) {
// Add a class to the cell based on the returned value
var testpattern = new RegExp ('test', 'i');
if (testpattern.test(cell.field))
{
// Update the cell content
$td.text(cell.value).addClass('string');
}
else {
var value = parseInt(cell.value);
if (value >= 1) {
$td.addClass('range-cell').addClass('range-fail');
}
else {
$td.addClass('range-cell').addClass('range-pass');
}
// Update the cell content
$td.text(' ').addClass('string');
}
}
});
mvc.Components.get('highlight').getVisualization(function(tableView) {
// Add custom cell renderer, the table will re-render automatically.
tableView.addCellRenderer(new CustomRangeRenderer());
});
});
... View more