1 | <!DOCTYPE html>
|
2 | <html lang="en">
|
3 | <head>
|
4 | <meta charset="utf-8"/>
|
5 | <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover"/>
|
6 | <meta name="description" content="TypeScript: Using the RowResizingTool and ColumnResizingTool to allow the user to change the size of rows and columns in a Table Panel."/>
|
7 | <link rel="stylesheet" href="../assets/css/style.css"/>
|
8 |
|
9 | <title>Resizing Rows and Columns in a Table Panel</title>
|
10 | </head>
|
11 |
|
12 | <body>
|
13 |
|
14 | <nav id="navTop" class="w-full z-30 top-0 text-white bg-nwoods-primary">
|
15 | <div class="w-full container max-w-screen-lg mx-auto flex flex-wrap sm:flex-nowrap items-center justify-between mt-0 py-2">
|
16 | <div class="md:pl-4">
|
17 | <a class="text-white hover:text-white no-underline hover:no-underline
|
18 | font-bold text-2xl lg:text-4xl rounded-lg hover:bg-nwoods-secondary " href="../">
|
19 | <h1 class="mb-0 p-1 ">GoJS</h1>
|
20 | </a>
|
21 | </div>
|
22 | <button id="topnavButton" class="rounded-lg sm:hidden focus:outline-none focus:ring" aria-label="Navigation">
|
23 | <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
|
24 | <path id="topnavOpen" fill-rule="evenodd" d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z" clip-rule="evenodd"></path>
|
25 | <path id="topnavClosed" class="hidden" fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path>
|
26 | </svg>
|
27 | </button>
|
28 | <div id="topnavList" class="hidden sm:block items-center w-auto mt-0 text-white p-0 z-20">
|
29 | <ul class="list-reset list-none font-semibold flex justify-end flex-wrap sm:flex-nowrap items-center px-0 pb-0">
|
30 | <li class="p-1 sm:p-0"><a class="topnav-link" href="../learn/">Learn</a></li>
|
31 | <li class="p-1 sm:p-0"><a class="topnav-link" href="../samples/">Samples</a></li>
|
32 | <li class="p-1 sm:p-0"><a class="topnav-link" href="../intro/">Intro</a></li>
|
33 | <li class="p-1 sm:p-0"><a class="topnav-link" href="../api/">API</a></li>
|
34 | <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/products/register.html">Register</a></li>
|
35 | <li class="p-1 sm:p-0"><a class="topnav-link" href="../download.html">Download</a></li>
|
36 | <li class="p-1 sm:p-0"><a class="topnav-link" href="https://forum.nwoods.com/c/gojs/11">Forum</a></li>
|
37 | <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/contact.html"
|
38 | target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a></li>
|
39 | <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/sales/index.html"
|
40 | target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a></li>
|
41 | </ul>
|
42 | </div>
|
43 | </div>
|
44 | <hr class="border-b border-gray-600 opacity-50 my-0 py-0" />
|
45 | </nav>
|
46 | <div class="md:flex flex-col md:flex-row md:min-h-screen w-full max-w-screen-xl mx-auto">
|
47 | <div id="navSide" class="flex flex-col w-full md:w-48 text-gray-700 bg-white flex-shrink-0"></div>
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | <div class="p-4 w-full">
|
53 | <div id="sample">
|
54 | <div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:400px"></div>
|
55 | <p>
|
56 | This makes use of two tools, defined in their own files: <a href="ColumnResizingTool.ts">ColumnResizingTool.ts</a> and <a href="RowResizingTool.ts">RowResizingTool.ts</a>.
|
57 | Each tool adds an <a>Adornment</a> to a selected node that has a resize handle for each column or each row of a "Table" <a>Panel</a>.
|
58 | While resizing, you can press the Tab or the Delete key in order to stop the tool and restore the column or row to its natural size.
|
59 | </p>
|
60 | <p>
|
61 | This sample also adds TwoWay Bindings to the <a>RowColumnDefinition.width</a> property for the columns.
|
62 | Each column width is stored in the corresponding index of the node data's "widths" property, which must be an Array of numbers.
|
63 | The default value is NaN, allowing the column to occupy its natural width.
|
64 | Note that there are <b>no</b> Bindings for the row heights.
|
65 | </p>
|
66 | <p>The model data, automatically updated after each change or undo or redo:</p>
|
67 | <textarea id="mySavedModel" style="width:100%;height:300px"></textarea>
|
68 | <p>See also the <a href="../samples/addRemoveColumns.html">Add & Remove Rows & Columns</a> sample.</p>
|
69 | </div>
|
70 |
|
71 | <script type="module" id="code">
|
72 | import * as go from "../release/go-module.js";
|
73 | import { ColumnResizingTool } from './ColumnResizingTool.js';
|
74 | import { RowResizingTool } from './RowResizingTool.js';
|
75 |
|
76 | if (window.goSamples) goSamples();
|
77 | const $ = go.GraphObject.make;
|
78 |
|
79 | const myDiagram = $(go.Diagram, 'myDiagramDiv', {
|
80 | validCycle: go.Diagram.CycleNotDirected,
|
81 | 'undoManager.isEnabled': true
|
82 | });
|
83 | myDiagram.toolManager.mouseDownTools.add(new RowResizingTool());
|
84 | myDiagram.toolManager.mouseDownTools.add(new ColumnResizingTool());
|
85 |
|
86 |
|
87 | const fieldTemplate = $(go.Panel, 'TableRow',
|
88 | new go.Binding('portId', 'name'),
|
89 | {
|
90 | background: 'transparent',
|
91 | fromSpot: go.Spot.Right,
|
92 | toSpot: go.Spot.Left,
|
93 |
|
94 | fromLinkable: true, toLinkable: true
|
95 | }, $(go.Shape, {
|
96 | column: 0,
|
97 | width: 12, height: 12, margin: 4,
|
98 |
|
99 | fromLinkable: false, toLinkable: false
|
100 | }, new go.Binding('figure', 'figure'), new go.Binding('fill', 'color')), $(go.TextBlock, {
|
101 | column: 1,
|
102 | margin: new go.Margin(0, 2),
|
103 | stretch: go.GraphObject.Horizontal,
|
104 | font: 'bold 13px sans-serif',
|
105 | wrap: go.TextBlock.None,
|
106 | overflow: go.TextBlock.OverflowEllipsis,
|
107 |
|
108 | fromLinkable: false, toLinkable: false
|
109 | }, new go.Binding('text', 'name')), $(go.TextBlock, {
|
110 | column: 2,
|
111 | margin: new go.Margin(0, 2),
|
112 | stretch: go.GraphObject.Horizontal,
|
113 | font: '13px sans-serif',
|
114 | maxLines: 3,
|
115 | overflow: go.TextBlock.OverflowEllipsis,
|
116 | editable: true
|
117 | }, new go.Binding('text', 'info').makeTwoWay()));
|
118 |
|
119 |
|
120 | function makeWidthBinding(idx) {
|
121 |
|
122 |
|
123 | function getColumnWidth(arr) {
|
124 | if (Array.isArray(arr) && idx < arr.length)
|
125 | return arr[idx];
|
126 | return NaN;
|
127 | }
|
128 |
|
129 | function setColumnWidth(w, data) {
|
130 | let arr = data.widths;
|
131 | if (!arr)
|
132 | arr = [];
|
133 | if (idx >= arr.length) {
|
134 | for (let i = arr.length; i <= idx; i++)
|
135 | arr[i] = NaN;
|
136 | }
|
137 | arr[idx] = w;
|
138 | return arr;
|
139 | }
|
140 | return [
|
141 | { column: idx },
|
142 | new go.Binding('width', 'widths', getColumnWidth).makeTwoWay(setColumnWidth)
|
143 | ];
|
144 | }
|
145 |
|
146 | myDiagram.nodeTemplate =
|
147 | $(go.Node, 'Auto', new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
|
148 |
|
149 | $(go.Shape, { fill: '#EEEEEE' }),
|
150 |
|
151 | $(go.Panel, 'Vertical', { stretch: go.GraphObject.Horizontal, alignment: go.Spot.TopLeft },
|
152 |
|
153 | $(go.Panel, 'Auto', { stretch: go.GraphObject.Horizontal },
|
154 | $(go.Shape, { fill: '#1570A6', stroke: null }), $(go.TextBlock, {
|
155 | alignment: go.Spot.Center,
|
156 | margin: 3,
|
157 | stroke: 'white',
|
158 | textAlign: 'center',
|
159 | font: 'bold 12pt sans-serif'
|
160 | }, new go.Binding('text', 'key'))),
|
161 |
|
162 |
|
163 | $(go.Panel, 'Table', {
|
164 | name: 'TABLE', stretch: go.GraphObject.Horizontal,
|
165 | minSize: new go.Size(100, 10),
|
166 | defaultAlignment: go.Spot.Left,
|
167 | defaultStretch: go.GraphObject.Horizontal,
|
168 | defaultColumnSeparatorStroke: 'gray',
|
169 | defaultRowSeparatorStroke: 'gray',
|
170 | itemTemplate: fieldTemplate
|
171 | }, $(go.RowColumnDefinition, makeWidthBinding(0)), $(go.RowColumnDefinition, makeWidthBinding(1)), $(go.RowColumnDefinition, makeWidthBinding(2)), new go.Binding('itemArray', 'fields'))
|
172 | )
|
173 | );
|
174 | myDiagram.linkTemplate =
|
175 | $(go.Link, { relinkableFrom: true, relinkableTo: true, toShortLength: 4 },
|
176 | $(go.Shape, { strokeWidth: 1.5 }), $(go.Shape, { toArrow: 'Standard', stroke: null }));
|
177 | myDiagram.model =
|
178 | $(go.GraphLinksModel, {
|
179 | linkFromPortIdProperty: 'fromPort',
|
180 | linkToPortIdProperty: 'toPort',
|
181 |
|
182 | 'Changed': function (e) {
|
183 | if (e.isTransactionFinished)
|
184 | showModel();
|
185 | },
|
186 | nodeDataArray: [
|
187 | {
|
188 | key: 'Record1',
|
189 | widths: [NaN, NaN, 60],
|
190 | fields: [
|
191 | { name: 'field1', info: 'first field', color: '#F7B84B', figure: 'Ellipse' },
|
192 | { name: 'field2', info: 'the second one', color: '#F25022', figure: 'Ellipse' },
|
193 | { name: 'fieldThree', info: '3rd', color: '#00BCF2' }
|
194 | ],
|
195 | loc: '0 0'
|
196 | },
|
197 | {
|
198 | key: 'Record2',
|
199 | widths: [NaN, NaN, NaN],
|
200 | fields: [
|
201 | { name: 'fieldA', info: '', color: '#FFB900', figure: 'Diamond' },
|
202 | { name: 'fieldB', info: '', color: '#F25022', figure: 'Rectangle' },
|
203 | { name: 'fieldC', info: '', color: '#7FBA00', figure: 'Diamond' },
|
204 | { name: 'fieldD', info: 'fourth', color: '#00BCF2', figure: 'Rectangle' }
|
205 | ],
|
206 | loc: '250 0'
|
207 | }
|
208 | ],
|
209 | linkDataArray: [
|
210 | { from: 'Record1', fromPort: 'field1', to: 'Record2', toPort: 'fieldA' },
|
211 | { from: 'Record1', fromPort: 'field2', to: 'Record2', toPort: 'fieldD' },
|
212 | { from: 'Record1', fromPort: 'fieldThree', to: 'Record2', toPort: 'fieldB' }
|
213 | ]
|
214 | });
|
215 | showModel();
|
216 | function showModel() {
|
217 | const elt = document.getElementById('mySavedModel');
|
218 | if (elt !== null)
|
219 | elt.textContent = myDiagram.model.toJson();
|
220 | }
|
221 |
|
222 | window.myDiagram = myDiagram;
|
223 | </script>
|
224 | </div>
|
225 |
|
226 |
|
227 | </div>
|
228 | </body>
|
229 |
|
230 | <script src="../assets/js/goSamples.js"></script>
|
231 | </html>
|