[Seating map] Add new table

I want to add a new table.
I tried this but not working:

       function createTable(){
            //alert("Hello world");
            console.log(myDiagram.model.Ce);
            const l1 = {
                    "key": 5,
                    "category": "TableC8",
                    "name": "Line 5",
                    "guests": {},
                    "loc": "564.5 423.5"
                };
            
            myDiagram.model.Ce.push(l1);
            myDiagram.requestUpdate(true);
        }

As clearly stated in GoJS Introduction -- Northwoods Software, your code must not refer to any of the minimized properties – it must only use the official API at GoJS API or at https://gojs.net/latest/release/go.d.ts.

Also, as stated in GoJS Using Models -- Northwoods Software, you cannot modify data without calling Model methods. Otherwise there is no way for the model to know that anything has changed, and thus there is no way for any diagram to know that its model has changed.

1 Like

Thanks you,
I use addNodeData. It works now.

    function createTable(){
        //alert("Hello world");
        console.log(myDiagram.model.Ce);
        const l1 = {
                "key": 5,
                "category": "TableC8",
                "name": "Line 5",
                "guests": {},
                "loc": "564.5 423.5"
            };
        
        myDiagram.model.addNodeData(l1);
        //myDiagram.requestUpdate(true);
    }

By the way, you should perform all changes within a transaction: GoJS Transactions -- Northwoods Software

The end of the transaction will make sure everything is updated.