Forum Discussion

Ophir_Buchman's avatar
Ophir_Buchman
Data Integration
03-07-2022

Pivot 2.0 - Replace the "-" Sign of a Negative Value by Parentheses

In Accounting, it is common to represent negative numbers with leading and trailing parentheses.
For example, negative two hundred is displayed as "(200)"

To change a negative number formatting in a pivot 2.0 chart - Add the following script to the pivot widget:

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 = doc.querySelectorAll('.table-grid__cell');
negative_cells = Array.from(cells).filter(cell => !isNaN(parseInt(cell.innerText.replaceAll(',',''))) && parseInt(cell.innerText.replaceAll(',',''))<0)

negative_cells.forEach(function(element) {
element.lastChild.innerText = element.lastChild.innerText.replace('-','(') + ')';
});
}
catch (error) {
debugger;
console.error(error);
}
finally {
console.log('DOM Ready script complete (wid=' + widget.oid + ')');
}
});
Before After

1 Reply

Replies have been turned off for this discussion
  • I have used the script to replace "-" with () for negative values. But it causes the values in the pivot table not refreshing properly in my dashboard when I switched the filters from one to another in my dropdown option.