@spectrum-web-components/table 0.0.2-table.2609 → 0.0.2-table.2625
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +151 -63
- package/custom-elements.json +86 -59
- package/package.json +2 -9
- package/src/Table.d.ts +24 -0
- package/src/Table.js +68 -65
- package/src/Table.js.map +1 -1
- package/src/TableBody.js +1 -1
- package/src/TableBody.js.map +1 -1
- package/src/TableCell.d.ts +0 -1
- package/src/TableCell.js +0 -4
- package/src/TableCell.js.map +1 -1
- package/src/TableCheckboxCell.d.ts +1 -1
- package/src/TableCheckboxCell.js +8 -11
- package/src/TableCheckboxCell.js.map +1 -1
- package/src/TableHead.d.ts +1 -0
- package/src/TableHead.js +1 -1
- package/src/TableHead.js.map +1 -1
- package/src/TableHeadCell.d.ts +2 -1
- package/src/TableHeadCell.js +2 -4
- package/src/TableHeadCell.js.map +1 -1
- package/src/TableRow.d.ts +2 -0
- package/src/TableRow.js +2 -0
- package/src/TableRow.js.map +1 -1
- package/src/spectrum-config.js +10 -7
- package/src/spectrum-table-head-cell.css.js +1 -1
- package/src/spectrum-table-head-cell.css.js.map +1 -1
- package/src/spectrum-table.css.js +83 -103
- package/src/spectrum-table.css.js.map +1 -1
- package/src/table-checkbox-cell.css.js +1 -1
- package/src/table-checkbox-cell.css.js.map +1 -1
- package/src/table-head-cell.css.js +1 -1
- package/src/table-head-cell.css.js.map +1 -1
- package/src/table.css.js +83 -103
- package/src/table.css.js.map +1 -1
- package/stories/index.js +0 -12
- package/stories/index.js.map +1 -1
- package/stories/table-elements.stories.js +46 -21
- package/stories/table-elements.stories.js.map +1 -1
- package/stories/table-virtualized.stories.js +38 -25
- package/stories/table-virtualized.stories.js.map +1 -1
- package/test/benchmark/basic-test.js +39 -1
- package/test/benchmark/basic-test.js.map +1 -1
- package/test/table.test.js +75 -649
- package/test/table.test.js.map +1 -1
- package/test/virtualized-table.test.js +494 -0
- package/test/virtualized-table.test.js.map +1 -0
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
To ensure that the table scrolls, make sure to add a `style` attribute to `<sp-table>` with your desired height. Otherwise, the table will automatically show all its items.
|
|
43
43
|
|
|
44
44
|
```html
|
|
45
|
-
<sp-table size="m"
|
|
45
|
+
<sp-table size="m">
|
|
46
46
|
<sp-table-head>
|
|
47
47
|
<sp-table-head-cell>Column Title</sp-table-head-cell>
|
|
48
48
|
<sp-table-head-cell>Column Title</sp-table-head-cell>
|
|
@@ -78,55 +78,12 @@ To ensure that the table scrolls, make sure to add a `style` attribute to `<sp-t
|
|
|
78
78
|
</sp-table>
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
## Sorting
|
|
82
|
-
|
|
83
|
-
For each table column you want to sort, use the `sortable` attribute in its respective `<sp-table-head-cell>`. `sort-direction="asc"|"desc"` specifies the direction the sort goes, in either ascending or descending order, respectively. The `@sorted` event listener on `<sp-table>` can be utilised to specify a method to fire when the `<sp-table-head-cell>` dispatches the `sorted` event. To specify which aspect of an item you'd like to sort by, use the `sort-key` attribute.
|
|
84
|
-
|
|
85
|
-
```html
|
|
86
|
-
<sp-table size="m" style="height: 120px">
|
|
87
|
-
<sp-table-head>
|
|
88
|
-
<sp-table-head-cell sortable sort-direction="asc">
|
|
89
|
-
Column Title
|
|
90
|
-
</sp-table-head-cell>
|
|
91
|
-
<sp-table-head-cell>Column Title</sp-table-head-cell>
|
|
92
|
-
<sp-table-head-cell>Column Title</sp-table-head-cell>
|
|
93
|
-
</sp-table-head>
|
|
94
|
-
<sp-table-body>
|
|
95
|
-
<sp-table-row>
|
|
96
|
-
<sp-table-cell>Row Item Bravo</sp-table-cell>
|
|
97
|
-
<sp-table-cell>Row Item Bravo</sp-table-cell>
|
|
98
|
-
<sp-table-cell>Row Item Bravo</sp-table-cell>
|
|
99
|
-
</sp-table-row>
|
|
100
|
-
<sp-table-row>
|
|
101
|
-
<sp-table-cell>Row Item Alpha</sp-table-cell>
|
|
102
|
-
<sp-table-cell>Row Item Alpha</sp-table-cell>
|
|
103
|
-
<sp-table-cell>Row Item Alpha</sp-table-cell>
|
|
104
|
-
</sp-table-row>
|
|
105
|
-
<sp-table-row>
|
|
106
|
-
<sp-table-cell>Row Item Charlie</sp-table-cell>
|
|
107
|
-
<sp-table-cell>Row Item Charlie</sp-table-cell>
|
|
108
|
-
<sp-table-cell>Row Item Charlie</sp-table-cell>
|
|
109
|
-
</sp-table-row>
|
|
110
|
-
<sp-table-row>
|
|
111
|
-
<sp-table-cell>Row Item Delta</sp-table-cell>
|
|
112
|
-
<sp-table-cell>Row Item Delta</sp-table-cell>
|
|
113
|
-
<sp-table-cell>Row Item Delta</sp-table-cell>
|
|
114
|
-
</sp-table-row>
|
|
115
|
-
<sp-table-row>
|
|
116
|
-
<sp-table-cell>Row Item Echo</sp-table-cell>
|
|
117
|
-
<sp-table-cell>Row Item Echo</sp-table-cell>
|
|
118
|
-
<sp-table-cell>Row Item Echo</sp-table-cell>
|
|
119
|
-
</sp-table-row>
|
|
120
|
-
</sp-table-body>
|
|
121
|
-
</sp-table>
|
|
122
|
-
```
|
|
123
|
-
|
|
124
81
|
## Selection
|
|
125
82
|
|
|
126
83
|
To manage selection on an `<sp-table>`, utilise the `selects` attribute on `<sp-table>`. Each `<sp-table-row>` has a `value` attribute which, by default, corresponds to its index in the table, and these `value`s tell `<sp-table>` which `<sp-table-row>`s are selected. The selected items can be manually fed in through the `.selected` attribute on the table.
|
|
127
84
|
|
|
128
85
|
```html
|
|
129
|
-
<sp-table size="m"
|
|
86
|
+
<sp-table size="m">
|
|
130
87
|
<sp-table-head>
|
|
131
88
|
<sp-table-head-cell sortable sort>Column Title</sp-table-head-cell>
|
|
132
89
|
<sp-table-head-cell>Column Title</sp-table-head-cell>
|
|
@@ -169,8 +126,8 @@ To manage selection on an `<sp-table>`, utilise the `selects` attribute on `<sp-
|
|
|
169
126
|
size="m"
|
|
170
127
|
selects="single"
|
|
171
128
|
selected='["row1"]'
|
|
172
|
-
style="height:
|
|
173
|
-
onchange="spAlert(`Selected: ${JSON.stringify(this.selected)`)"
|
|
129
|
+
style="height: 200px"
|
|
130
|
+
onchange="spAlert(this, `Selected: ${JSON.stringify(this.selected)}`)"
|
|
174
131
|
>
|
|
175
132
|
<sp-table-head>
|
|
176
133
|
<sp-table-head-cell>Column Title</sp-table-head-cell>
|
|
@@ -214,10 +171,10 @@ When `selects` is set to "multiple", the `<sp-table-checkbox-cell>` in `<sp-tabl
|
|
|
214
171
|
```html
|
|
215
172
|
<sp-table
|
|
216
173
|
size="m"
|
|
217
|
-
style="height:
|
|
174
|
+
style="height: 200px"
|
|
218
175
|
selects="multiple"
|
|
219
176
|
selected='["row1", "row2"]'
|
|
220
|
-
onchange="spAlert(`Selected: ${JSON.stringify(this.selected)`)"
|
|
177
|
+
onchange="spAlert(this, `Selected: ${JSON.stringify(this.selected)}`)"
|
|
221
178
|
>
|
|
222
179
|
<sp-table-head>
|
|
223
180
|
<sp-table-head-cell>Column Title</sp-table-head-cell>
|
|
@@ -262,6 +219,8 @@ For large amounts of data, the `<sp-table>` can be virtualised to easily add tab
|
|
|
262
219
|
<sp-table
|
|
263
220
|
size="m"
|
|
264
221
|
id="table-virtualized-demo"
|
|
222
|
+
style="height: 200px"
|
|
223
|
+
scroller="true"
|
|
265
224
|
>
|
|
266
225
|
<sp-table-head>
|
|
267
226
|
<sp-table-head-cell>Column Title</sp-table-head-cell>
|
|
@@ -296,7 +255,9 @@ For large amounts of data, the `<sp-table>` can be virtualised to easily add tab
|
|
|
296
255
|
return [cell1, cell2, cell3];
|
|
297
256
|
}
|
|
298
257
|
};
|
|
299
|
-
|
|
258
|
+
customElements.whenDefined('sp-table').then(() => {
|
|
259
|
+
initTable();
|
|
260
|
+
});
|
|
300
261
|
</script>
|
|
301
262
|
```
|
|
302
263
|
|
|
@@ -314,7 +275,6 @@ For large amounts of data, the `<sp-table>` can be virtualised to easily add tab
|
|
|
314
275
|
return items;
|
|
315
276
|
}
|
|
316
277
|
|
|
317
|
-
}
|
|
318
278
|
const initTable = () => {
|
|
319
279
|
const table = document.querySelector('#table-virtualized-demo');
|
|
320
280
|
table.items = initItems(50);
|
|
@@ -329,12 +289,14 @@ For large amounts of data, the `<sp-table>` can be virtualised to easily add tab
|
|
|
329
289
|
return [cell1, cell2, cell3];
|
|
330
290
|
}
|
|
331
291
|
};
|
|
332
|
-
|
|
292
|
+
customElements.whenDefined('sp-table').then(() => {
|
|
293
|
+
initTable();
|
|
294
|
+
});
|
|
333
295
|
</script>
|
|
334
296
|
|
|
335
297
|
### How to use it
|
|
336
298
|
|
|
337
|
-
The virtualised table takes
|
|
299
|
+
The virtualised table takes `items` as either a property or a JSON-encoded string, an array of type `Record`, where the key is a `string` and the value can be whatever you'd like. `items` is then fed into the `renderItem` method, which takes an `item` and its `index` as parameters and renders the `<sp-table-row>` for each item. An example is as follows:
|
|
338
300
|
|
|
339
301
|
```javascript
|
|
340
302
|
const renderItem = (item: Item, index: number): TemplateResult => {
|
|
@@ -346,19 +308,145 @@ const renderItem = (item: Item, index: number): TemplateResult => {
|
|
|
346
308
|
};
|
|
347
309
|
```
|
|
348
310
|
|
|
349
|
-
|
|
311
|
+
`renderItem` is then included as a property of `<sp-table>`, along with the `items`, to render a full `<sp-table>` without excessive manual HTML writing.
|
|
312
|
+
|
|
313
|
+
You can also render a different cell at a particular index by doing something like below:
|
|
314
|
+
|
|
315
|
+
```javascript
|
|
316
|
+
const renderItem = (item: Item, index: number): TemplateResult => {
|
|
317
|
+
if (index === 15) {
|
|
318
|
+
return html`
|
|
319
|
+
<sp-table-cell style="text-align: center">Custom Row</sp-table-cell>
|
|
320
|
+
`;
|
|
321
|
+
}
|
|
322
|
+
return html`
|
|
323
|
+
<sp-table-cell>Row Item ${item.name}</sp-table-cell>
|
|
324
|
+
<sp-table-cell>Row Item ${item.date}</sp-table-cell>
|
|
325
|
+
<sp-table-cell>Row Item ${index}</sp-table-cell>
|
|
326
|
+
`;
|
|
327
|
+
};
|
|
328
|
+
```
|
|
350
329
|
|
|
351
330
|
Please note that there is a bug when attempting to select all virtualised elements. The items are selected programatically, it's just not reflected visually.
|
|
352
331
|
|
|
353
|
-
|
|
332
|
+
### The `scroller` property
|
|
333
|
+
|
|
334
|
+
By default, the virtualized table doesn't contain a scroll bar and will display the entire length of the table body. Use the `scroller` property and specify an inline style for the height to get a `Table` of your desired height that scrolls.
|
|
335
|
+
|
|
336
|
+
## Sorting on the Virtualized Table
|
|
337
|
+
|
|
338
|
+
The virtualized table supports sorting its elements.
|
|
339
|
+
|
|
340
|
+
For each table column you want to sort, use the `sortable` attribute in its respective `<sp-table-head-cell>`. `sort-direction="asc"|"desc"` specifies the direction the sort goes, in either ascending or descending order, respectively. The `@sorted` event listener on `<sp-table>` can be utilised to specify a method to fire when the `<sp-table-head-cell>` dispatches the `sorted` event. To specify which aspect of an item you'd like to sort by, use the `sort-key` attribute.
|
|
341
|
+
|
|
342
|
+
```html-live
|
|
343
|
+
<sp-table
|
|
344
|
+
size="m"
|
|
345
|
+
id="sorted-virtualized-table"
|
|
346
|
+
style="height: 200px"
|
|
347
|
+
scroller="true"
|
|
348
|
+
>
|
|
349
|
+
<sp-table-head>
|
|
350
|
+
<sp-table-head-cell sortable sort-direction="desc" sort-key="name">
|
|
351
|
+
Sortable Column
|
|
352
|
+
</sp-table-head-cell>
|
|
353
|
+
<sp-table-head-cell>Non-sortable Column</sp-table-head-cell>
|
|
354
|
+
<sp-table-head-cell>Non-sortable Column</sp-table-head-cell>
|
|
355
|
+
</sp-table-head>
|
|
356
|
+
</sp-table>
|
|
357
|
+
<script type="module">
|
|
358
|
+
const initItems = (count) => {
|
|
359
|
+
const total = count;
|
|
360
|
+
const items = [];
|
|
361
|
+
while (count) {
|
|
362
|
+
count--;
|
|
363
|
+
items.push({
|
|
364
|
+
name: String(total - count),
|
|
365
|
+
date: count,
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
return items;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
let items = initItems(50);
|
|
354
372
|
|
|
355
|
-
|
|
373
|
+
const initTable = () => {
|
|
374
|
+
const table = document.querySelector('#sorted-virtualized-table');
|
|
356
375
|
|
|
357
|
-
|
|
376
|
+
table.items = items;
|
|
358
377
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
378
|
+
table.renderItem = (item, index) => {
|
|
379
|
+
const cell1 = document.createElement('sp-table-cell');
|
|
380
|
+
const cell2 = document.createElement('sp-table-cell');
|
|
381
|
+
const cell3 = document.createElement('sp-table-cell');
|
|
382
|
+
cell1.textContent = `Row Item Alpha ${item.name}`;
|
|
383
|
+
cell2.textContent = `Row Item Beta ${item.date}`;
|
|
384
|
+
cell3.textContent = `Index: ${index}`;
|
|
385
|
+
return [cell1, cell2, cell3];
|
|
386
|
+
}
|
|
387
|
+
table.addEventListener('sorted', (event) => {
|
|
388
|
+
const { sortDirection, sortKey } = event.detail;
|
|
389
|
+
items = items.sort((a, b) => {
|
|
390
|
+
const first = String(a[sortKey]);
|
|
391
|
+
const second = String(b[sortKey]);
|
|
392
|
+
return sortDirection === 'asc'
|
|
393
|
+
? first.localeCompare(second)
|
|
394
|
+
: second.localeCompare(first);
|
|
395
|
+
});
|
|
396
|
+
table.items = [...items];
|
|
397
|
+
});
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
customElements.whenDefined('sp-table').then(() => {
|
|
401
|
+
initTable();
|
|
402
|
+
});
|
|
403
|
+
</script>
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
<script type="module">
|
|
407
|
+
const initItems = (count) => {
|
|
408
|
+
const total = count;
|
|
409
|
+
const items = [];
|
|
410
|
+
while (count) {
|
|
411
|
+
count--;
|
|
412
|
+
items.push({
|
|
413
|
+
name: String(total - count),
|
|
414
|
+
date: count,
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
return items;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
let items = initItems(50);
|
|
421
|
+
|
|
422
|
+
const initTable = () => {
|
|
423
|
+
const table = document.querySelector('#sorted-virtualized-table');
|
|
424
|
+
|
|
425
|
+
table.items = items;
|
|
426
|
+
|
|
427
|
+
table.renderItem = (item, index) => {
|
|
428
|
+
const cell1 = document.createElement('sp-table-cell');
|
|
429
|
+
const cell2 = document.createElement('sp-table-cell');
|
|
430
|
+
const cell3 = document.createElement('sp-table-cell');
|
|
431
|
+
cell1.textContent = `Row Item Alpha ${item.name}`;
|
|
432
|
+
cell2.textContent = `Row Item Beta ${item.date}`;
|
|
433
|
+
cell3.textContent = `Index: ${index}`;
|
|
434
|
+
return [cell1, cell2, cell3];
|
|
435
|
+
}
|
|
436
|
+
table.addEventListener('sorted', (event) => {
|
|
437
|
+
const { sortDirection, sortKey } = event.detail;
|
|
438
|
+
items = items.sort((a, b) => {
|
|
439
|
+
const first = String(a[sortKey]);
|
|
440
|
+
const second = String(b[sortKey]);
|
|
441
|
+
return sortDirection === 'asc'
|
|
442
|
+
? first.localeCompare(second)
|
|
443
|
+
: second.localeCompare(first);
|
|
444
|
+
});
|
|
445
|
+
table.items = [...items];
|
|
446
|
+
});
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
customElements.whenDefined('sp-table').then(() => {
|
|
450
|
+
initTable();
|
|
451
|
+
});
|
|
452
|
+
</script>
|
package/custom-elements.json
CHANGED
|
@@ -183,6 +183,7 @@
|
|
|
183
183
|
"text": "undefined | 'single' | 'multiple'"
|
|
184
184
|
},
|
|
185
185
|
"privacy": "public",
|
|
186
|
+
"description": "Whether the Table allows users to select a row or rows, and thus controls whether or not the Table also renders checkboxes.",
|
|
186
187
|
"attribute": "selects",
|
|
187
188
|
"reflects": true
|
|
188
189
|
},
|
|
@@ -194,6 +195,7 @@
|
|
|
194
195
|
},
|
|
195
196
|
"privacy": "public",
|
|
196
197
|
"default": "[]",
|
|
198
|
+
"description": "An array of <sp-row> values that have been selected.",
|
|
197
199
|
"attribute": "selected"
|
|
198
200
|
},
|
|
199
201
|
{
|
|
@@ -210,14 +212,27 @@
|
|
|
210
212
|
},
|
|
211
213
|
"privacy": "public",
|
|
212
214
|
"default": "[]",
|
|
215
|
+
"description": "The content of the rows rendered by the virtualized table. The key is the value of the sp-table-row, and the value is the sp-table-row's content (not the row itself).",
|
|
213
216
|
"attribute": "items"
|
|
214
217
|
},
|
|
215
218
|
{
|
|
216
219
|
"kind": "field",
|
|
217
220
|
"name": "itemValue",
|
|
218
221
|
"privacy": "public",
|
|
222
|
+
"description": "The value of an item. By default, it is set to the index of the sp-table-row.",
|
|
219
223
|
"attribute": "itemValue"
|
|
220
224
|
},
|
|
225
|
+
{
|
|
226
|
+
"kind": "field",
|
|
227
|
+
"name": "scroller",
|
|
228
|
+
"type": {
|
|
229
|
+
"text": "boolean"
|
|
230
|
+
},
|
|
231
|
+
"privacy": "public",
|
|
232
|
+
"default": "false",
|
|
233
|
+
"description": "Whether or not the virtualized table has a scroll bar. If this is set to true, make sure to specify a height in the sp-table's inline styles.",
|
|
234
|
+
"attribute": "scroller"
|
|
235
|
+
},
|
|
221
236
|
{
|
|
222
237
|
"kind": "field",
|
|
223
238
|
"name": "tableBody",
|
|
@@ -234,6 +249,22 @@
|
|
|
234
249
|
},
|
|
235
250
|
"privacy": "private"
|
|
236
251
|
},
|
|
252
|
+
{
|
|
253
|
+
"kind": "field",
|
|
254
|
+
"name": "tableHead",
|
|
255
|
+
"type": {
|
|
256
|
+
"text": "TableHead"
|
|
257
|
+
},
|
|
258
|
+
"privacy": "private"
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
"kind": "field",
|
|
262
|
+
"name": "tableRows",
|
|
263
|
+
"type": {
|
|
264
|
+
"text": "TableRow[]"
|
|
265
|
+
},
|
|
266
|
+
"privacy": "private"
|
|
267
|
+
},
|
|
237
268
|
{
|
|
238
269
|
"kind": "field",
|
|
239
270
|
"name": "isVirtualized",
|
|
@@ -302,6 +333,24 @@
|
|
|
302
333
|
}
|
|
303
334
|
}
|
|
304
335
|
},
|
|
336
|
+
{
|
|
337
|
+
"kind": "method",
|
|
338
|
+
"name": "manageHeadCheckbox",
|
|
339
|
+
"privacy": "protected",
|
|
340
|
+
"return": {
|
|
341
|
+
"type": {
|
|
342
|
+
"text": "void"
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
"parameters": [
|
|
346
|
+
{
|
|
347
|
+
"name": "allSelected",
|
|
348
|
+
"type": {
|
|
349
|
+
"text": "boolean"
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
]
|
|
353
|
+
},
|
|
305
354
|
{
|
|
306
355
|
"kind": "method",
|
|
307
356
|
"name": "handleChange",
|
|
@@ -364,12 +413,17 @@
|
|
|
364
413
|
"name": "change",
|
|
365
414
|
"type": {
|
|
366
415
|
"text": "Event"
|
|
367
|
-
}
|
|
416
|
+
},
|
|
417
|
+
"description": "Announces a change in the `selected` property of a table row"
|
|
368
418
|
},
|
|
369
419
|
{
|
|
370
420
|
"type": {
|
|
371
421
|
"text": "RangeChangedEvent"
|
|
372
422
|
}
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
"description": "Announces a change in the range of visible cells on the table body",
|
|
426
|
+
"name": "rangeChanged"
|
|
373
427
|
}
|
|
374
428
|
],
|
|
375
429
|
"attributes": [
|
|
@@ -386,6 +440,7 @@
|
|
|
386
440
|
"type": {
|
|
387
441
|
"text": "undefined | 'single' | 'multiple'"
|
|
388
442
|
},
|
|
443
|
+
"description": "Whether the Table allows users to select a row or rows, and thus controls whether or not the Table also renders checkboxes.",
|
|
389
444
|
"fieldName": "selects"
|
|
390
445
|
},
|
|
391
446
|
{
|
|
@@ -394,6 +449,7 @@
|
|
|
394
449
|
"text": "string[]"
|
|
395
450
|
},
|
|
396
451
|
"default": "[]",
|
|
452
|
+
"description": "An array of <sp-row> values that have been selected.",
|
|
397
453
|
"fieldName": "selected"
|
|
398
454
|
},
|
|
399
455
|
{
|
|
@@ -402,11 +458,22 @@
|
|
|
402
458
|
"text": "Record<string, unknown>[]"
|
|
403
459
|
},
|
|
404
460
|
"default": "[]",
|
|
461
|
+
"description": "The content of the rows rendered by the virtualized table. The key is the value of the sp-table-row, and the value is the sp-table-row's content (not the row itself).",
|
|
405
462
|
"fieldName": "items"
|
|
406
463
|
},
|
|
407
464
|
{
|
|
408
465
|
"name": "itemValue",
|
|
466
|
+
"description": "The value of an item. By default, it is set to the index of the sp-table-row.",
|
|
409
467
|
"fieldName": "itemValue"
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
"name": "scroller",
|
|
471
|
+
"type": {
|
|
472
|
+
"text": "boolean"
|
|
473
|
+
},
|
|
474
|
+
"default": "false",
|
|
475
|
+
"description": "Whether or not the virtualized table has a scroll bar. If this is set to true, make sure to specify a height in the sp-table's inline styles.",
|
|
476
|
+
"fieldName": "scroller"
|
|
410
477
|
}
|
|
411
478
|
],
|
|
412
479
|
"superclass": {
|
|
@@ -505,17 +572,6 @@
|
|
|
505
572
|
"default": "'gridcell'",
|
|
506
573
|
"attribute": "role",
|
|
507
574
|
"reflects": true
|
|
508
|
-
},
|
|
509
|
-
{
|
|
510
|
-
"kind": "field",
|
|
511
|
-
"name": "tabIndex",
|
|
512
|
-
"type": {
|
|
513
|
-
"text": "number"
|
|
514
|
-
},
|
|
515
|
-
"privacy": "public",
|
|
516
|
-
"default": "-1",
|
|
517
|
-
"attribute": "tabIndex",
|
|
518
|
-
"reflects": true
|
|
519
575
|
}
|
|
520
576
|
],
|
|
521
577
|
"attributes": [
|
|
@@ -526,14 +582,6 @@
|
|
|
526
582
|
},
|
|
527
583
|
"default": "'gridcell'",
|
|
528
584
|
"fieldName": "role"
|
|
529
|
-
},
|
|
530
|
-
{
|
|
531
|
-
"name": "tabIndex",
|
|
532
|
-
"type": {
|
|
533
|
-
"text": "number"
|
|
534
|
-
},
|
|
535
|
-
"default": "-1",
|
|
536
|
-
"fieldName": "tabIndex"
|
|
537
585
|
}
|
|
538
586
|
],
|
|
539
587
|
"superclass": {
|
|
@@ -575,17 +623,6 @@
|
|
|
575
623
|
"attribute": "role",
|
|
576
624
|
"reflects": true
|
|
577
625
|
},
|
|
578
|
-
{
|
|
579
|
-
"kind": "field",
|
|
580
|
-
"name": "tabIndex",
|
|
581
|
-
"type": {
|
|
582
|
-
"text": "number"
|
|
583
|
-
},
|
|
584
|
-
"privacy": "public",
|
|
585
|
-
"default": "-1",
|
|
586
|
-
"attribute": "tabIndex",
|
|
587
|
-
"reflects": true
|
|
588
|
-
},
|
|
589
626
|
{
|
|
590
627
|
"kind": "field",
|
|
591
628
|
"name": "checkbox",
|
|
@@ -634,6 +671,16 @@
|
|
|
634
671
|
"default": "false",
|
|
635
672
|
"attribute": "selects-single",
|
|
636
673
|
"reflects": true
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
"kind": "method",
|
|
677
|
+
"name": "handleChange",
|
|
678
|
+
"privacy": "protected",
|
|
679
|
+
"return": {
|
|
680
|
+
"type": {
|
|
681
|
+
"text": "void"
|
|
682
|
+
}
|
|
683
|
+
}
|
|
637
684
|
}
|
|
638
685
|
],
|
|
639
686
|
"events": [
|
|
@@ -653,14 +700,6 @@
|
|
|
653
700
|
"default": "'gridcell'",
|
|
654
701
|
"fieldName": "role"
|
|
655
702
|
},
|
|
656
|
-
{
|
|
657
|
-
"name": "tabIndex",
|
|
658
|
-
"type": {
|
|
659
|
-
"text": "number"
|
|
660
|
-
},
|
|
661
|
-
"default": "-1",
|
|
662
|
-
"fieldName": "tabIndex"
|
|
663
|
-
},
|
|
664
703
|
{
|
|
665
704
|
"name": "indeterminate",
|
|
666
705
|
"type": {
|
|
@@ -867,17 +906,6 @@
|
|
|
867
906
|
"default": "''",
|
|
868
907
|
"attribute": "sort-key"
|
|
869
908
|
},
|
|
870
|
-
{
|
|
871
|
-
"kind": "field",
|
|
872
|
-
"name": "tabIndex",
|
|
873
|
-
"type": {
|
|
874
|
-
"text": "number"
|
|
875
|
-
},
|
|
876
|
-
"privacy": "public",
|
|
877
|
-
"default": "-1",
|
|
878
|
-
"attribute": "tabIndex",
|
|
879
|
-
"reflects": true
|
|
880
|
-
},
|
|
881
909
|
{
|
|
882
910
|
"kind": "method",
|
|
883
911
|
"name": "handleClick",
|
|
@@ -894,7 +922,8 @@
|
|
|
894
922
|
"name": "sorted",
|
|
895
923
|
"type": {
|
|
896
924
|
"text": "CustomEvent"
|
|
897
|
-
}
|
|
925
|
+
},
|
|
926
|
+
"description": "Announces that the table head has been sorted and handles the sorted event"
|
|
898
927
|
}
|
|
899
928
|
],
|
|
900
929
|
"attributes": [
|
|
@@ -928,14 +957,6 @@
|
|
|
928
957
|
},
|
|
929
958
|
"default": "''",
|
|
930
959
|
"fieldName": "sortKey"
|
|
931
|
-
},
|
|
932
|
-
{
|
|
933
|
-
"name": "tabIndex",
|
|
934
|
-
"type": {
|
|
935
|
-
"text": "number"
|
|
936
|
-
},
|
|
937
|
-
"default": "-1",
|
|
938
|
-
"fieldName": "tabIndex"
|
|
939
960
|
}
|
|
940
961
|
],
|
|
941
962
|
"superclass": {
|
|
@@ -1034,6 +1055,12 @@
|
|
|
1034
1055
|
}
|
|
1035
1056
|
}
|
|
1036
1057
|
],
|
|
1058
|
+
"events": [
|
|
1059
|
+
{
|
|
1060
|
+
"description": "Announces that `selected` of the table row has changed",
|
|
1061
|
+
"name": "sorted"
|
|
1062
|
+
}
|
|
1063
|
+
],
|
|
1037
1064
|
"attributes": [
|
|
1038
1065
|
{
|
|
1039
1066
|
"name": "role",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/table",
|
|
3
|
-
"version": "0.0.2-table.
|
|
3
|
+
"version": "0.0.2-table.2625+0c83ba2e6",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -23,19 +23,12 @@
|
|
|
23
23
|
".": "./src/index.js",
|
|
24
24
|
"./src/*": "./src/*.js",
|
|
25
25
|
"./package.json": "./package.json",
|
|
26
|
-
"./sp-table-body": "./sp-table-body.js",
|
|
27
26
|
"./sp-table-body.js": "./sp-table-body.js",
|
|
28
|
-
"./sp-table-cell": "./sp-table-cell.js",
|
|
29
27
|
"./sp-table-cell.js": "./sp-table-cell.js",
|
|
30
|
-
"./sp-table-checkbox-cell": "./sp-table-checkbox-cell.js",
|
|
31
28
|
"./sp-table-checkbox-cell.js": "./sp-table-checkbox-cell.js",
|
|
32
|
-
"./sp-table-head": "./sp-table-head.js",
|
|
33
29
|
"./sp-table-head.js": "./sp-table-head.js",
|
|
34
|
-
"./sp-table-head-cell": "./sp-table-head-cell.js",
|
|
35
30
|
"./sp-table-head-cell.js": "./sp-table-head-cell.js",
|
|
36
|
-
"./sp-table-row": "./sp-table-row.js",
|
|
37
31
|
"./sp-table-row.js": "./sp-table-row.js",
|
|
38
|
-
"./sp-table": "./sp-table.js",
|
|
39
32
|
"./sp-table.js": "./sp-table.js"
|
|
40
33
|
},
|
|
41
34
|
"scripts": {
|
|
@@ -70,5 +63,5 @@
|
|
|
70
63
|
"sideEffects": [
|
|
71
64
|
"./sp-*.js"
|
|
72
65
|
],
|
|
73
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "0c83ba2e61dcd1713c08495ea92ee1a8531c1123"
|
|
74
67
|
}
|
package/src/Table.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { CSSResultArray, PropertyValues, SpectrumElement, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
+
import '../sp-table-row.js';
|
|
3
|
+
import '../sp-table-checkbox-cell.js';
|
|
2
4
|
interface Range {
|
|
3
5
|
first: number;
|
|
4
6
|
last: number;
|
|
@@ -11,6 +13,9 @@ export declare class RangeChangedEvent extends Event {
|
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
15
|
* @element sp-table
|
|
16
|
+
*
|
|
17
|
+
* @fires rangeChanged - Announces a change in the range of visible cells on the table body
|
|
18
|
+
* @event change - Announces a change in the `selected` property of a table row
|
|
14
19
|
*/
|
|
15
20
|
export declare class Table extends SpectrumElement {
|
|
16
21
|
static get styles(): CSSResultArray;
|
|
@@ -18,13 +23,31 @@ export declare class Table extends SpectrumElement {
|
|
|
18
23
|
set renderItem(fn: (item: Record<string, unknown>, index: number) => TemplateResult);
|
|
19
24
|
private _renderItem;
|
|
20
25
|
role: string;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the Table allows users to select a row or rows, and thus controls whether or not the Table also renders checkboxes.
|
|
28
|
+
*/
|
|
21
29
|
selects: undefined | 'single' | 'multiple';
|
|
30
|
+
/**
|
|
31
|
+
* An array of <sp-row> values that have been selected.
|
|
32
|
+
*/
|
|
22
33
|
selected: string[];
|
|
23
34
|
private selectedSet;
|
|
35
|
+
/**
|
|
36
|
+
* The content of the rows rendered by the virtualized table. The key is the value of the sp-table-row, and the value is the sp-table-row's content (not the row itself).
|
|
37
|
+
*/
|
|
24
38
|
items: Record<string, unknown>[];
|
|
39
|
+
/**
|
|
40
|
+
* The value of an item. By default, it is set to the index of the sp-table-row.
|
|
41
|
+
*/
|
|
25
42
|
itemValue: (_item: unknown, index: number) => string;
|
|
43
|
+
/**
|
|
44
|
+
* Whether or not the virtualized table has a scroll bar. If this is set to true, make sure to specify a height in the sp-table's inline styles.
|
|
45
|
+
*/
|
|
46
|
+
scroller: boolean;
|
|
26
47
|
private tableBody?;
|
|
27
48
|
private tableHeadCheckboxCell?;
|
|
49
|
+
private get tableHead();
|
|
50
|
+
private get tableRows();
|
|
28
51
|
private get isVirtualized();
|
|
29
52
|
focus(): void;
|
|
30
53
|
private selectAllRows;
|
|
@@ -32,6 +55,7 @@ export declare class Table extends SpectrumElement {
|
|
|
32
55
|
protected manageSelects(): void;
|
|
33
56
|
protected manageSelected(): void;
|
|
34
57
|
protected manageCheckboxes(): void;
|
|
58
|
+
protected manageHeadCheckbox(allSelected: boolean): void;
|
|
35
59
|
protected handleChange(event: Event): void;
|
|
36
60
|
scrollToIndex(index?: number): void;
|
|
37
61
|
protected render(): TemplateResult;
|