Forum Discussion
JeremyFriedel
10-28-2024Sisense Employee
Yes, this is possible, the example and article linked here is an example of this functionality.
This script example in question is below:
widget.on('domready', function (se, ev) {
const alignNumbersToTheRight = () => {
console.log('aligning numbers to the right...')
$('td', element).each(function () {
if (/^[0-9,.]*$/.test($(this).text())) {
$(this).css('text-align', 'right')
}
})
}
alignNumbersToTheRight()
// Observe changes in the table body
const elementToObserve = $('table tbody', element)[0]
const observer = new MutationObserver(function (e) {
alignNumbersToTheRight()
})
observer.observe(elementToObserve, { subtree: true, childList: true });
})
Modifying the example to log the values is straightforward, as shown below:
widget.on('domready', function (se, ev) {
const exampleFunction = () => {
console.log('Observing Cells')
$('td', element).each(function () {
if (/^[0-9,.]*$/.test($(this).text())) {
console.log('Cell Value is ', $(this).text())
}
})
}
exampleFunction()
// Observe changes in the table body
const elementToObserve = $('table tbody', element)[0]
const observer = new MutationObserver(function (e) {
exampleFunction()
})
observer.observe(elementToObserve, { subtree: true, childList: true });
})
Many customization scripts that would potentially involve a MutationObserver with a Pivot table type widget can instead use the Pivot 2.0 API which can be more straightforward.