Ophir_Buchman
03-09-2022Data Integration
Pivot 2.0 - Add Conditional Formatting to the Sub/Grand-Total Rows
When attempting to apply formatting to a Pivot 2.0 chart you might find out that it doesn't apply to the Sub-Total and Grand-Total rows. The following (widget) code applies conditional formatting to negative numbers:
function getWidgetDocumentObject(widget) {
if (prism.activeWidget == null)
return document.querySelector('[widgetid="' + widget.oid + '"]').querySelector('pivot2');
else
return document.querySelector('pivot2');
}
widget.on('domready', function(widget) {
try {
console.log('DOM Ready script starting (wid=' + widget.oid + ')');
doc = getWidgetDocumentObject(widget);
cells = Array.from($('.table-grid__cell--row-user-type-grandTotal, .table-grid__cell--row-user-type-subTotal'))
cells.forEach(function(element) {
if(element.innerText.startsWith('-'))
element.lastChild.setAttribute('style','color:red')
})
});
}
catch (error) {
debugger;
console.error(error);
}
finally {
console.log('DOM Ready script complete (wid=' + widget.oid + ')');
}
});
Before | After |