File size: 816 Bytes
34a7685
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function executeScriptFormatter(cell, formatterParams, onRendered) {
    onRendered(function(){
        const shadowRoot = cell.getElement().getRootNode();
        if (shadowRoot instanceof ShadowRoot) {
            const script = cell.getElement().querySelector('script');
            if (script) {
                // Replace "document." with "shadowRoot." in the script code
                const scriptCode = script.innerText.replace(/document\./g, 'shadowRoot.');
                // Execute the modified script code
                const func = new Function('shadowRoot', scriptCode);
                func(shadowRoot);
            }
        }
    });
    return cell.getValue();
};



Tabulator.extendModule("format", "formatters", {
    executeScriptFormatter: executeScriptFormatter,
});