Hi to all,
I am struggling to find a way to determine when a view’s summary section has completed its calculations and finished its rendering.
I wish so badly that there was a built-in event like this one in Knack:
$(document).on('knack-summary-render.view_1', function (event, view, data) {
console.log('Summary has completed rendering in view_1');
})
A summary rendered event would be so useful !
Currently, I use a mutation observer as taught by David R. (HMND). A big thank you again David! This works ok, but I get 8 notifications for the 4 rows. Probably due to the 8 values.
See this screen grab:
This is the code:
var observer = null;
if (!observer) {
observer = new MutationObserver((mutations) => {
mutations.forEach(mutRec => {
const knView = mutRec.target.closest('.kn-view');
var viewId = (knView && knView.id);
if (viewId) {
var view = Knack.views[viewId];
if (view && typeof view.model === 'object') {
if (viewId && mutRec.target.localName === 'tbody') {
if (mutRec.addedNodes.length && mutRec.addedNodes[0].classList && mutRec.addedNodes[0].classList.contains('kn-table-totals')) {
console.log('Rendering .kn-table-totals');
}
}
}
}
});
})
observer.observe(document.querySelector('.kn-content'), {
childList: true,
subtree: true,
});
}
Is there an internal Knack function that does what I want, or do I have to manually trim this to work as intended?
All I want is to take action after the 4 rows are done rendering.
Currently, I can achieve my goal, but I get some annoying flickering due to the multiple renderings.
I can’t rely on hard coded timing, since the summary takes a long and non-deterministic time to render, depending on the complexity and quantity or records to be processed.
Thanks,
Normand