简体   繁体   中英

Webcomponent support for Tabulator Table

I would like to use the very nice Tabulator ( http://tabulator.info/ ) javascript table in a webcomponent.

However it looks like the main Tabulator instance can only be created via a html selector like this:

var table = new Tabulator("#example-table", {...});

Unfortunately looks like the #example-table is not visible in the shadowDom of webcomponents:

class WcProjects extends HTMLElement {
    constructor() {
        super();
        // Attach a shadow root to the element.
        let shadowRoot = this.attachShadow({mode: 'open'});
        shadowRoot.innerHTML = `<div id="example-table"></div>`;
}
connectedCallback() {
    var table = new Tabulator("#example-table", {...});
}

Is there another way of instantiating the Tabulator table?

Any help is much appreciated.

The Tabulator constructor accepts either a selector or a DOM node into the constructor element of the table, ie:

var tableHolder = document.createElement("div");
var table = new Tabulator(tableHolder , {...});

so as long as you have access to that node, which your component should give you, you can pass that into the constructor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM