JLedgerwood
10-23-2024Data Storage
Usage of MutationObserver in Pivot2 Widget
Is it possible to use the MutationObserver in a Pivot2 Widget? Using the code below, I'm not seeing the log statements within the console from within the "each". By step debugging I can see that the MutationObserver is created but the loop is not getting executed even once. My Pivot table has five rows and the elementToObserve variable is created and is valid. I've tried the "domready" event and the "initialized" event but the same issue persists, the loop is not run. I have verified that the Pivot table is within a "table body" so that selector is fine. Any help is greatly appreviated.
widget.on('ready', function (ev, se) {
console.log("ready");
const elementToObserve = $('table tbody', element)[0];
const linkObserver = new MutationObserver(function(elements) {
for(const element of elements) {
console.log("ready-MutationObserver ");
if (element.type === 'childList') {
$.each(element.addedNodes, function(index, value){
console.log("ready-MutationObserver value is " + value);
});
}
}
});
linkObserver.observe(elementToObserve, {subtree: true, childList: true});
});