gojs实现可编辑的table表格效果代码
代码语言:html
所属分类:表格
代码描述:gojs实现可编辑的table表格效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0" /> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/go.js"></script> </head> <body> <div id="myDiagramDiv" style="height:100vh;width:100vw;"> </div> <script type="text/javascript"> function init() { if (window.goSamples) goSamples(); // init for these samples -- you don't need to call this var $ = go.GraphObject.make; myDiagram = $(go.Diagram, "myDiagramDiv", { "undoManager.isEnabled": true }); myDiagram.nodeTemplate = $(go.Node, "Auto", $(go.Shape, { fill: "white" }), $(go.Panel, "Table", new go.Binding("itemArray", "people"), $(go.RowColumnDefinition, { row: 0, background: "lightgray" }), $(go.RowColumnDefinition, { row: 1, separatorStroke: "black" }), // the table headers -- remains even if itemArray is empty $(go.Panel, "TableRow", { isPanelMain: true }, new go.Binding("itemArray", "columnDefinitions"), { itemTemplate: // bound to a column definition object $(go.Panel, new go.Binding("column"), $(go.TextBlock, { margin: new go.Margin(2, 2, 0, 2), font: "bold 10pt sans-serif" }, new go.Binding("text")) ) } ), { // the rows for the people defaultAlignment: go.Spot.Left, defaultColumnSeparatorStroke: "black", itemTemplate: // bound to a person/row data object $(go.Panel, "TableRow", // which in turn consists of a collection of cell objects, // held by the "columns" property in an Array new go.Binding("itemArray", "columns"), // you could also have other Bindings here for the whole row { itemTemplate: // bound to a cell object $(go.Panel, // each of which as "attr" and "text" properties { stretch: go.GraphObject.Fill, alignment: go.Spot.TopLeft }, new go.Binding("column", "attr", function(a, elt) { // ELT is this bound item/cell Panel // elt.data will be the cell object // elt.panel.data will be the person/row data object // elt.part.data will be the node data object // "columnDefinitions" is on the node data object, so: var cd = findColumnDefinitionForName(elt.part.data, a); if (cd !== null) return cd.column; throw new Error("unknown column name: " + a); }), // you could also have other Bindings here for this cell $(go.TextBlock, { editable: true }, { margin: new go.Margin(2, 2, 0, 2), wrap: go.TextBlock.None }, new go.Binding("text").makeTwoWay()) ) } ) } ) ); myDiagram.model = $(go.GraphLinksModel, { copiesArrays: true, copiesArrayObjects: true, nodeDataArray: [ { // first node key: 1, columnDefinitions: [ // each column definition needs to specify the column used { attr: "name", text: "Name", column: 0 }, { attr: "phone", text: "Phone #", column: 1 }, { attr: "office", text: "Office", column: 2 } ], people: [ // the table of people // each row is a person with an Array of Objects associating a column name with a text value { columns: [{ attr: "name", text: "Alice" }, { attr: "phone", text: "2345" }, { attr: "office", text: "C4-E18" }] }, { columns: [{ attr: "name", text: "Bob" }, { attr: "phone", text: "9876" }, { attr: "office", text: "E1-B34" }] }, { columns: [{ attr: "name", text: "Carol" }, { attr: "phone", text: "1111" }, { attr: "office", text: "C4-E23" }] }, { columns: [{ attr: "name", text: "Ted" }, { attr: "phone", text: "2222" }, { attr: "office", text: "C4-E197" }] } ] }, { // second node key: 2, columnDefinitions: [ { attr: "name", text: "Name", column: 0 }, { attr: "p.........完整代码请登录后点击上方下载按钮下载查看
网友评论0