nested table contents from pages or snippets using Model SDK

1
Hi all, we're trying to get nested table contents from pages or snippets from the API but when we request the widget property, table cells only return undefined. When using traverse (but not traversePublic) we do see all nested elements but this method provides insufficient control (only a callback method accepting IStructure objects which then gets called for the entire tree). How can we get a cell's contents using the TableCell object? Thanks in advance!
asked
1 answers
3

I have indirectly received a test project from you containing the following page:

I then wrote a little script to inspect this page to see whether I could get to the table contents:

 

project.createWorkingCopy()
    .then((workingCopy) => {
        const module = workingCopy.model().allModules().filter(m => m.name === "PCP_Statistics")[ 0 ];
        const _snippet = module.documents.filter(d => d.name === "CompanyStatistics")[0] as pages.ISnippet;
        return loadAsPromise(_snippet).then(snippet => {
            dumpTable(0, snippet.widget as pages.Table);
            return workingCopy;
        });
    })
    .done(() => {
        console.log(`success!`);
    }, (error) => {
        console.log(`error: ${error}`);
    });
 
function dumpTable(depth: number, table: pages.Table) {
    for (let i = 0; i < table.cells.length; i++) {
        const widget = table.cells[i].widget;
        console.log(depth + " " + " cell " + i + " contains " + widget.typeName);
        if (widget instanceof pages.Table) {
            dumpTable(depth + 1, widget);
        }
    }
}

The output of this script is:

0  cell 0 contains Pages$Table
1  cell 0 contains Pages$Table
2  cell 0 contains Pages$ActionButton
2  cell 1 contains Pages$TabContainer

Which is what I would expect. Is this what you were looking for?

answered