简体   繁体   中英

How can I delete a row from a Scrolling Table in Gojs?

I'm using Scrolling Table in Gojs to draw links between the rows of two tables (let's say Input and Output tables). Both Input and Output tables are drawn using Scrolling-Table functionality in Gojs.

Now I want to delete a row from Output table but technically I haven't found any way to do this because each table acts a Gojs Node and when I click on a row, it selects the whole table (Node) instead of that particular row.

Here is my code:

var nodeJson;
        var $ = go.GraphObject.make;
        var inputFieldTable = [
            { ID: "001", Name: "Input 1", Text: "Err1" },
            { ID: "002", Name: "Input 2", Text: "Err2" },
            { ID: "003", Name: "Input 3", Text: "Err3" },
            { ID: "004", Name: "Input 4", Text: "Err4" },
            { ID: "005", Name: "Input 5", Text: "Err5" },
            { ID: "006", Name: "Input 6", Text: "Err6" },
            { ID: "007", Name: "Input 7", Text: "Err7" }
        ];

        var outputFieldTable = [
            { ID: "101", Name: "Output 1", Text: "Integer" },
            { ID: "102", Name: "Output 2", Text: "Integer" },
            { ID: "103", Name: "Output 3", Text: "Integer" },
            { ID: "104", Name: "Output 4", Text: "String" },
            { ID: "105", Name: "Output 5", Text: "String" },
            { ID: "106", Name: "Output 6", Text: "Double" },
            { ID: "107", Name: "Output 7", Text: "Multivalue" }
        ];
        myDiagram =
            $(go.Diagram, "myDiagramDiv",
                {
                    initialContentAlignment: go.Spot.Center,
                    "undoManager.isEnabled": true,
                    allowMove: false,
                    allowDelete: true,
                    allowCopy: false,
                    allowDragOut: false,
                    allowDrop: false
                });

        myDiagram.nodeTemplate =
            $(go.Node, "Vertical",
                {
                    selectionObjectName: "SCROLLING",
                    resizable: false, resizeObjectName: "SCROLLING",
                    portSpreading: go.Node.SpreadingNone
                },
                new go.Binding("location").makeTwoWay(),
                $(go.TextBlock,
                    { font: "bold 14px sans-serif" },
                    new go.Binding("text", "key")),
                $(go.Panel, "Auto",
                    $(go.Shape, { fill: "white" }),
                    $("ScrollingTable",
                        { stretch: go.GraphObject.Fill },
                        new go.Binding("TABLE.itemArray", "items"),
                        new go.Binding("TABLE.column", "left", function (left) { return left ? 2 : 0; }),
                        new go.Binding("desiredSize", "size").makeTwoWay(),
                        {
                            name: "SCROLLING",
                            desiredSize: new go.Size(100, 100),
                            "TABLE.itemTemplate":
                            $(go.Panel, "TableRow",
                                {
                                    defaultStretch: go.GraphObject.Horizontal,
                                    fromSpot: go.Spot.LeftRightSides,
                                    toSpot: go.Spot.LeftRightSides,
                                    fromLinkable: true,
                                    toLinkable: true,
                                    //allowDelete: true,
                                    //isGroup: true,
                                },
                                new go.Binding("portId", "Name"),
                                $(go.TextBlock, { column: 1 }, new go.Binding("text", "Name")),
                                $(go.TextBlock, { column: 2 }, new go.Binding("text", "Text"))
                            ),
                            "TABLE.defaultColumnSeparatorStroke": "gray",
                            "TABLE.defaultColumnSeparatorStrokeWidth": 0.5,
                            "TABLE.defaultRowSeparatorStroke": "gray",
                            "TABLE.defaultRowSeparatorStrokeWidth": 0.5,
                            "TABLE.defaultSeparatorPadding": new go.Margin(1, 3, 0, 3)
                        }
                    )
                )
            );

        myDiagram.model = $(go.GraphLinksModel,
            {
                linkFromPortIdProperty: "fromPort",
                linkToPortIdProperty: "toPort",
                nodeDataArray: [
                    {
                        key: "Input", left: true, location: new go.Point(0, 0), size: new go.Size(170, 100),
                        items: inputFieldTable
                    },
                    {
                        key: "Output", location: new go.Point(300, 0), size: new go.Size(170, 100),
                        items: outputFieldTable
                    }
                ]
            });

http://gojs.net/latest/samples/selectableFields.html demonstrates how to do that.

Basically you support highlighting individual fields and keep track of those that are highlighted within a node, effectively forming a collection of all highlighted fields. Then you can override the CommandHandler.deleteSelection method to delete selected fields, if there are any, rather than deleting selected nodes.

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