|
7 | 7 | <title>Grid Pro</title> |
8 | 8 | <link rel="stylesheet" href="/packages/vaadin-lumo-styles/lumo.css" /> |
9 | 9 | <script type="module" src="./common.js"></script> |
| 10 | + |
| 11 | + <style> |
| 12 | + .controls { |
| 13 | + display: grid; |
| 14 | + grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); |
| 15 | + gap: 2rem; |
| 16 | + margin-bottom: 2rem; |
| 17 | + font-size: 0.875rem; |
| 18 | + } |
| 19 | + |
| 20 | + .control-group { |
| 21 | + display: flex; |
| 22 | + flex-direction: column; |
| 23 | + gap: 1em; |
| 24 | + } |
| 25 | + |
| 26 | + .control-group h3 { |
| 27 | + margin-top: 0; |
| 28 | + font-size: var(--lumo-font-size-m); |
| 29 | + } |
| 30 | + |
| 31 | + vaadin-grid-pro.auto-width { |
| 32 | + width: fit-content; |
| 33 | + } |
| 34 | + |
| 35 | + vaadin-grid-pro.max-width { |
| 36 | + max-width: 50%; |
| 37 | + } |
| 38 | + |
| 39 | + vaadin-grid-pro.max-height { |
| 40 | + max-height: 250px; |
| 41 | + } |
| 42 | + </style> |
10 | 43 | </head> |
11 | 44 | <body> |
12 | | - <vaadin-grid-pro single-cell-edit> |
13 | | - <vaadin-grid-pro-edit-column path="name.first"></vaadin-grid-pro-edit-column> |
14 | | - <vaadin-grid-pro-edit-column path="name.last"></vaadin-grid-pro-edit-column> |
| 45 | + <div class="controls"> |
| 46 | + <div class="control-group"> |
| 47 | + <vaadin-checkbox-group label="Sizing"> |
| 48 | + <vaadin-checkbox id="autoWidth" value="autoWidth" label="Auto Width"></vaadin-checkbox> |
| 49 | + <vaadin-checkbox id="all-rows" value="all-rows" label="Auto Height"></vaadin-checkbox> |
| 50 | + <vaadin-checkbox id="maxWidth" value="maxWidth" label="Max Width"></vaadin-checkbox> |
| 51 | + <vaadin-checkbox id="maxHeight" value="maxHeight" label="Max Height"></vaadin-checkbox> |
| 52 | + </vaadin-checkbox-group> |
| 53 | + |
| 54 | + <vaadin-radio-group id="items" label="Items"> |
| 55 | + <vaadin-checkbox id="details" value="details" label="Details"></vaadin-checkbox> |
| 56 | + </vaadin-radio-group> |
| 57 | + </div> |
| 58 | + |
| 59 | + <div class="control-group"> |
| 60 | + <vaadin-checkbox-group label="Column Features"> |
| 61 | + <vaadin-checkbox id="header" value="header" label="Header" checked></vaadin-checkbox> |
| 62 | + <vaadin-checkbox id="footer" value="footer" label="Footer"></vaadin-checkbox> |
| 63 | + <vaadin-checkbox id="autoWidthCols" value="autoWidth" label="Auto Width"></vaadin-checkbox> |
| 64 | + <vaadin-checkbox id="resizable" value="resizable" label="Resizable"></vaadin-checkbox> |
| 65 | + <vaadin-checkbox id="frozen" value="frozen" label="Freeze First Name Column"></vaadin-checkbox> |
| 66 | + <vaadin-checkbox id="frozenEnd" value="frozenEnd" label="Freeze Married Column"></vaadin-checkbox> |
| 67 | + </vaadin-checkbox-group> |
| 68 | + <vaadin-select id="textAlign" label="Text Align"></vaadin-select> |
| 69 | + </div> |
| 70 | + |
| 71 | + <div class="control-group"> |
| 72 | + <vaadin-checkbox-group label="Theme Variants"> |
| 73 | + <vaadin-checkbox value="no-border" label="No Border"></vaadin-checkbox> |
| 74 | + <vaadin-checkbox value="no-row-borders" label="No Row Border"></vaadin-checkbox> |
| 75 | + <vaadin-checkbox value="column-borders" label="Column Borders"></vaadin-checkbox> |
| 76 | + <vaadin-checkbox value="row-stripes" label="Row Stripes"></vaadin-checkbox> |
| 77 | + <vaadin-checkbox value="wrap-cell-content" label="Wrap Cell Content"></vaadin-checkbox> |
| 78 | + <vaadin-checkbox value="highlight-editable-cells" label="Highlight Editable Cells"></vaadin-checkbox> |
| 79 | + <vaadin-checkbox value="highlight-read-only-cells" label="Highlight Read-Only Cells"></vaadin-checkbox> |
| 80 | + </vaadin-checkbox-group> |
| 81 | + </div> |
| 82 | + |
| 83 | + <div class="control-group"> |
| 84 | + <vaadin-radio-group id="dropMode" label="Drop Mode"> |
| 85 | + <vaadin-radio-button value="none" label="None"></vaadin-radio-button> |
| 86 | + <vaadin-radio-button value="on-grid" label="On Grid"></vaadin-radio-button> |
| 87 | + <vaadin-radio-button value="between" label="Between" checked></vaadin-radio-button> |
| 88 | + <vaadin-radio-button value="on-top" label="On Top"></vaadin-radio-button> |
| 89 | + </vaadin-radio-group> |
| 90 | + </div> |
| 91 | + </div> |
| 92 | + |
| 93 | + <vaadin-grid-pro single-cell-edit column-reordering-allowed> |
| 94 | + <vaadin-grid-selection-column></vaadin-grid-selection-column> |
| 95 | + <vaadin-grid-pro-edit-column path="name.first" header="First Name"></vaadin-grid-pro-edit-column> |
| 96 | + <vaadin-grid-pro-edit-column path="name.last" header="Last Name"></vaadin-grid-pro-edit-column> |
15 | 97 | <vaadin-grid-pro-edit-column |
16 | 98 | path="name.title" |
| 99 | + header="Title" |
17 | 100 | editor-type="select" |
18 | 101 | editor-options='["mr", "mrs", "ms"]' |
19 | 102 | ></vaadin-grid-pro-edit-column> |
| 103 | + <vaadin-grid-sort-column path="email" header="Email"></vaadin-grid-sort-column> |
20 | 104 | <vaadin-grid-pro-edit-column path="married" editor-type="checkbox"></vaadin-grid-pro-edit-column> |
21 | 105 | </vaadin-grid-pro> |
22 | 106 |
|
23 | 107 | <script type="module"> |
| 108 | + import '@vaadin/grid/all-imports'; |
| 109 | + import '@vaadin/checkbox'; |
| 110 | + import '@vaadin/checkbox-group'; |
| 111 | + import '@vaadin/radio-group'; |
| 112 | + import '@vaadin/select'; |
| 113 | + import '@vaadin/list-box'; |
24 | 114 | import '@vaadin/grid-pro'; |
25 | 115 | import '@vaadin/grid-pro/vaadin-grid-pro-edit-column.js'; |
26 | 116 | import { users } from '../packages/grid-pro/test/visual/users.js'; |
27 | 117 |
|
28 | 118 | const grid = document.querySelector('vaadin-grid-pro'); |
29 | 119 | grid.items = users; |
| 120 | + |
| 121 | + // Setup grid and controls |
| 122 | + const selectionColumn = grid.querySelector('vaadin-grid-selection-column'); |
| 123 | + |
| 124 | + // Setup row details renderer |
| 125 | + const rowDetailsRenderer = (root, grid, model) => { |
| 126 | + root.innerHTML = ` |
| 127 | + <div style="padding: 1rem"> |
| 128 | + <h4>Details for ${model.item.name}</h4> |
| 129 | + <p>Additional information could be shown here.</p> |
| 130 | + </div> |
| 131 | + `; |
| 132 | + }; |
| 133 | + |
| 134 | + // Setup selects |
| 135 | + const textAlignSelect = document.getElementById('textAlign'); |
| 136 | + textAlignSelect.items = [ |
| 137 | + { label: 'Start', value: 'start' }, |
| 138 | + { label: 'Center', value: 'center' }, |
| 139 | + { label: 'End', value: 'end' }, |
| 140 | + ]; |
| 141 | + |
| 142 | + // Enable drag and drop by default |
| 143 | + grid.rowsDraggable = true; |
| 144 | + grid.dropMode = 'between'; |
| 145 | + |
| 146 | + // Sizing Controls |
| 147 | + document.getElementById('autoWidth').addEventListener('checked-changed', (e) => { |
| 148 | + grid.classList.toggle('auto-width', e.detail.value); |
| 149 | + }); |
| 150 | + |
| 151 | + document.getElementById('all-rows').addEventListener('checked-changed', (e) => { |
| 152 | + grid.allRowsVisible = e.detail.value; |
| 153 | + }); |
| 154 | + |
| 155 | + document.getElementById('maxWidth').addEventListener('checked-changed', (e) => { |
| 156 | + grid.classList.toggle('max-width', e.detail.value); |
| 157 | + }); |
| 158 | + |
| 159 | + document.getElementById('maxHeight').addEventListener('checked-changed', (e) => { |
| 160 | + grid.classList.toggle('max-height', e.detail.value); |
| 161 | + }); |
| 162 | + |
| 163 | + document.getElementById('details').addEventListener('checked-changed', (e) => { |
| 164 | + grid.rowDetailsRenderer = e.detail.value ? rowDetailsRenderer : undefined; |
| 165 | + }); |
| 166 | + |
| 167 | + // Column Controls |
| 168 | + document.getElementById('header').addEventListener('checked-changed', (e) => { |
| 169 | + grid |
| 170 | + .querySelectorAll( |
| 171 | + 'vaadin-grid-column-group, vaadin-grid-column, vaadin-grid-tree-column, vaadin-grid-filter-column, vaadin-grid-sort-column, vaadin-grid-pro-edit-column', |
| 172 | + ) |
| 173 | + .forEach((col) => { |
| 174 | + col.__headerText = col.header ?? col.__headerText; |
| 175 | + col.header = e.detail.value ? col.__headerText : null; |
| 176 | + col.headerRenderer = e.detail.value |
| 177 | + ? (root) => { |
| 178 | + root.textContent = col.__headerText || col.path; |
| 179 | + } |
| 180 | + : null; |
| 181 | + }); |
| 182 | + }); |
| 183 | + |
| 184 | + document.getElementById('footer').addEventListener('checked-changed', (e) => { |
| 185 | + grid |
| 186 | + .querySelectorAll( |
| 187 | + 'vaadin-grid-column-group, vaadin-grid-column, vaadin-grid-tree-column, vaadin-grid-filter-column, vaadin-grid-sort-column, vaadin-grid-pro-edit-column', |
| 188 | + ) |
| 189 | + .forEach((col) => { |
| 190 | + col.__headerText = col.header ?? col.__headerText; |
| 191 | + col.footerRenderer = e.detail.value |
| 192 | + ? (root) => { |
| 193 | + root.textContent = col.__headerText ?? col.path; |
| 194 | + } |
| 195 | + : null; |
| 196 | + }); |
| 197 | + }); |
| 198 | + |
| 199 | + document.getElementById('autoWidthCols').addEventListener('checked-changed', (e) => { |
| 200 | + grid |
| 201 | + .querySelectorAll( |
| 202 | + 'vaadin-grid-column, vaadin-grid-tree-column, vaadin-grid-filter-column, vaadin-grid-sort-column, vaadin-grid-pro-edit-column', |
| 203 | + ) |
| 204 | + .forEach((col) => { |
| 205 | + col.autoWidth = e.detail.value; |
| 206 | + col.width = e.detail.value ? undefined : '100px'; |
| 207 | + col.flexGrow = 1; |
| 208 | + }); |
| 209 | + grid.recalculateColumnWidths(); |
| 210 | + }); |
| 211 | + |
| 212 | + document.getElementById('resizable').addEventListener('checked-changed', (e) => { |
| 213 | + grid |
| 214 | + .querySelectorAll( |
| 215 | + 'vaadin-grid-column, vaadin-grid-tree-column, vaadin-grid-filter-column, vaadin-grid-sort-column, vaadin-grid-pro-edit-column', |
| 216 | + ) |
| 217 | + .forEach((col) => { |
| 218 | + col.resizable = e.detail.value; |
| 219 | + }); |
| 220 | + }); |
| 221 | + |
| 222 | + document.getElementById('frozen').addEventListener('checked-changed', (e) => { |
| 223 | + const firstCol = grid.querySelector('vaadin-grid-pro-edit-column'); |
| 224 | + if (firstCol) { |
| 225 | + firstCol.frozen = e.detail.value; |
| 226 | + } |
| 227 | + // Also freeze the selection column |
| 228 | + const selectionColumn = grid.querySelector('vaadin-grid-selection-column'); |
| 229 | + if (selectionColumn) { |
| 230 | + selectionColumn.frozen = e.detail.value; |
| 231 | + } |
| 232 | + }); |
| 233 | + |
| 234 | + document.getElementById('frozenEnd').addEventListener('checked-changed', (e) => { |
| 235 | + const lastCol = Array.from(grid.querySelectorAll('vaadin-grid-pro-edit-column')).pop(); |
| 236 | + if (lastCol) { |
| 237 | + lastCol.frozenToEnd = e.detail.value; |
| 238 | + } |
| 239 | + }); |
| 240 | + |
| 241 | + document.getElementById('textAlign').addEventListener('value-changed', (e) => { |
| 242 | + grid |
| 243 | + .querySelectorAll('vaadin-grid-tree-column, vaadin-grid-sort-column, vaadin-grid-filter-column') |
| 244 | + .forEach((col) => { |
| 245 | + col.textAlign = e.detail.value; |
| 246 | + }); |
| 247 | + }); |
| 248 | + |
| 249 | + // Handle active item changes for details |
| 250 | + grid.addEventListener('active-item-changed', (e) => { |
| 251 | + const item = e.detail.value; |
| 252 | + grid.detailsOpenedItems = item ? [item] : []; |
| 253 | + }); |
| 254 | + |
| 255 | + // Drag & Drop Controls |
| 256 | + document.getElementById('dropMode').addEventListener('value-changed', (e) => { |
| 257 | + grid.dropMode = e.detail.value; |
| 258 | + }); |
| 259 | + |
| 260 | + // Theme Controls |
| 261 | + document.querySelectorAll('[label="Theme Variants"] vaadin-checkbox').forEach((control) => { |
| 262 | + control.addEventListener('checked-changed', (e) => { |
| 263 | + if (e.detail.value) { |
| 264 | + grid.setAttribute('theme', `${grid.getAttribute('theme') || ''} ${control.value}`.trim()); |
| 265 | + } else { |
| 266 | + grid.setAttribute('theme', (grid.getAttribute('theme') || '').replace(control.value, '').trim()); |
| 267 | + } |
| 268 | + }); |
| 269 | + }); |
30 | 270 | </script> |
31 | 271 | </body> |
32 | 272 | </html> |
0 commit comments