@vaadin/grid 24.2.0-alpha3 → 24.2.0-alpha5
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/package.json +11 -11
- package/src/lit/column-renderer-directives.d.ts +4 -5
- package/src/lit/renderer-directives.d.ts +6 -2
- package/src/vaadin-grid-column.d.ts +11 -0
- package/src/vaadin-grid-column.js +27 -0
- package/src/vaadin-grid-data-provider-mixin.js +4 -1
- package/src/vaadin-grid-selection-column-base-mixin.d.ts +57 -0
- package/src/vaadin-grid-selection-column-base-mixin.js +191 -0
- package/src/vaadin-grid-selection-column.d.ts +3 -12
- package/src/vaadin-grid-selection-column.js +39 -122
- package/web-types.json +94 -201
- package/web-types.lit.json +39 -81
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/grid",
|
|
3
|
-
"version": "24.2.0-
|
|
3
|
+
"version": "24.2.0-alpha5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -46,18 +46,18 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
48
48
|
"@polymer/polymer": "^3.0.0",
|
|
49
|
-
"@vaadin/a11y-base": "24.2.0-
|
|
50
|
-
"@vaadin/checkbox": "24.2.0-
|
|
51
|
-
"@vaadin/component-base": "24.2.0-
|
|
52
|
-
"@vaadin/lit-renderer": "24.2.0-
|
|
53
|
-
"@vaadin/text-field": "24.2.0-
|
|
54
|
-
"@vaadin/vaadin-lumo-styles": "24.2.0-
|
|
55
|
-
"@vaadin/vaadin-material-styles": "24.2.0-
|
|
56
|
-
"@vaadin/vaadin-themable-mixin": "24.2.0-
|
|
49
|
+
"@vaadin/a11y-base": "24.2.0-alpha5",
|
|
50
|
+
"@vaadin/checkbox": "24.2.0-alpha5",
|
|
51
|
+
"@vaadin/component-base": "24.2.0-alpha5",
|
|
52
|
+
"@vaadin/lit-renderer": "24.2.0-alpha5",
|
|
53
|
+
"@vaadin/text-field": "24.2.0-alpha5",
|
|
54
|
+
"@vaadin/vaadin-lumo-styles": "24.2.0-alpha5",
|
|
55
|
+
"@vaadin/vaadin-material-styles": "24.2.0-alpha5",
|
|
56
|
+
"@vaadin/vaadin-themable-mixin": "24.2.0-alpha5"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@esm-bundle/chai": "^4.3.4",
|
|
60
|
-
"@vaadin/testing-helpers": "^0.4.
|
|
60
|
+
"@vaadin/testing-helpers": "^0.4.3",
|
|
61
61
|
"lit": "^2.0.0",
|
|
62
62
|
"sinon": "^13.0.2"
|
|
63
63
|
},
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"web-types.json",
|
|
66
66
|
"web-types.lit.json"
|
|
67
67
|
],
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "73db22a5e8993e3ce48d1e6540d30eff9cb5c257"
|
|
69
69
|
}
|
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
/* eslint-disable max-classes-per-file */
|
|
7
|
-
import type { TemplateResult } from 'lit';
|
|
8
7
|
import type { DirectiveResult } from 'lit/directive';
|
|
9
|
-
import type { LitRenderer } from '@vaadin/lit-renderer';
|
|
8
|
+
import type { LitRenderer, LitRendererResult } from '@vaadin/lit-renderer';
|
|
10
9
|
import { LitRendererDirective } from '@vaadin/lit-renderer';
|
|
11
10
|
import type { GridItemModel } from '../vaadin-grid.js';
|
|
12
11
|
import type { GridColumn } from '../vaadin-grid-column.js';
|
|
@@ -15,10 +14,10 @@ export type GridColumnBodyLitRenderer<TItem> = (
|
|
|
15
14
|
item: TItem,
|
|
16
15
|
model: GridItemModel<TItem>,
|
|
17
16
|
column: GridColumn,
|
|
18
|
-
) =>
|
|
17
|
+
) => LitRendererResult;
|
|
19
18
|
|
|
20
|
-
export type GridColumnHeaderLitRenderer = (column: GridColumn) =>
|
|
21
|
-
export type GridColumnFooterLitRenderer = (column: GridColumn) =>
|
|
19
|
+
export type GridColumnHeaderLitRenderer = (column: GridColumn) => LitRendererResult;
|
|
20
|
+
export type GridColumnFooterLitRenderer = (column: GridColumn) => LitRendererResult;
|
|
22
21
|
|
|
23
22
|
declare abstract class AbstractGridColumnRendererDirective<R extends LitRenderer> extends LitRendererDirective<
|
|
24
23
|
GridColumn,
|
|
@@ -3,12 +3,16 @@
|
|
|
3
3
|
* Copyright (c) 2017 - 2023 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import type { TemplateResult } from 'lit';
|
|
7
6
|
import type { DirectiveResult } from 'lit/directive';
|
|
7
|
+
import type { LitRendererResult } from '@vaadin/lit-renderer';
|
|
8
8
|
import { LitRendererDirective } from '@vaadin/lit-renderer';
|
|
9
9
|
import type { Grid, GridItemModel } from '../vaadin-grid.js';
|
|
10
10
|
|
|
11
|
-
export type GridRowDetailsLitRenderer<TItem> = (
|
|
11
|
+
export type GridRowDetailsLitRenderer<TItem> = (
|
|
12
|
+
item: TItem,
|
|
13
|
+
model: GridItemModel<TItem>,
|
|
14
|
+
grid: Grid,
|
|
15
|
+
) => LitRendererResult;
|
|
12
16
|
|
|
13
17
|
export declare class GridRowDetailsRendererDirective<TItem> extends LitRendererDirective<
|
|
14
18
|
Grid,
|
|
@@ -43,6 +43,17 @@ export declare class ColumnBaseMixinClass<TItem> {
|
|
|
43
43
|
*/
|
|
44
44
|
frozenToEnd: boolean;
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* When true, the cells for this column will be rendered with the `role` attribute
|
|
48
|
+
* set as `rowheader`, instead of the `gridcell` role value used by default.
|
|
49
|
+
*
|
|
50
|
+
* When a column is set as row header, its cells will be announced by screen readers
|
|
51
|
+
* while navigating to help user identify the current row as uniquely as possible.
|
|
52
|
+
*
|
|
53
|
+
* @attr {boolean} row-header
|
|
54
|
+
*/
|
|
55
|
+
rowHeader: boolean;
|
|
56
|
+
|
|
46
57
|
/**
|
|
47
58
|
* When set to true, the cells for this column are hidden.
|
|
48
59
|
*/
|
|
@@ -61,6 +61,21 @@ export const ColumnBaseMixin = (superClass) =>
|
|
|
61
61
|
value: false,
|
|
62
62
|
},
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* When true, the cells for this column will be rendered with the `role` attribute
|
|
66
|
+
* set as `rowheader`, instead of the `gridcell` role value used by default.
|
|
67
|
+
*
|
|
68
|
+
* When a column is set as row header, its cells will be announced by screen readers
|
|
69
|
+
* while navigating to help user identify the current row as uniquely as possible.
|
|
70
|
+
*
|
|
71
|
+
* @attr {boolean} row-header
|
|
72
|
+
* @type {boolean}
|
|
73
|
+
*/
|
|
74
|
+
rowHeader: {
|
|
75
|
+
type: Boolean,
|
|
76
|
+
value: false,
|
|
77
|
+
},
|
|
78
|
+
|
|
64
79
|
/**
|
|
65
80
|
* When set to true, the cells for this column are hidden.
|
|
66
81
|
*/
|
|
@@ -222,6 +237,7 @@ export const ColumnBaseMixin = (superClass) =>
|
|
|
222
237
|
'_resizableChanged(resizable, _headerCell)',
|
|
223
238
|
'_reorderStatusChanged(_reorderStatus, _headerCell, _footerCell, _cells.*)',
|
|
224
239
|
'_hiddenChanged(hidden, _headerCell, _footerCell, _cells.*)',
|
|
240
|
+
'_rowHeaderChanged(rowHeader, _cells.*)',
|
|
225
241
|
];
|
|
226
242
|
}
|
|
227
243
|
|
|
@@ -407,6 +423,17 @@ export const ColumnBaseMixin = (superClass) =>
|
|
|
407
423
|
}
|
|
408
424
|
}
|
|
409
425
|
|
|
426
|
+
/** @private */
|
|
427
|
+
_rowHeaderChanged(rowHeader, cells) {
|
|
428
|
+
if (!cells.value) {
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
cells.value.forEach((cell) => {
|
|
433
|
+
cell.setAttribute('role', rowHeader ? 'rowheader' : 'gridcell');
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
|
|
410
437
|
/**
|
|
411
438
|
* @param {string} path
|
|
412
439
|
* @return {string}
|
|
@@ -398,7 +398,10 @@ export const DataProviderMixin = (superClass) =>
|
|
|
398
398
|
}
|
|
399
399
|
|
|
400
400
|
// Populate the cache with new items
|
|
401
|
-
|
|
401
|
+
items.forEach((item, itemsIndex) => {
|
|
402
|
+
const itemIndex = page * this.pageSize + itemsIndex;
|
|
403
|
+
cache.items[itemIndex] = item;
|
|
404
|
+
});
|
|
402
405
|
|
|
403
406
|
// With the new items added, update the cache size and the grid's effective size
|
|
404
407
|
this._cache.updateSize();
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 - 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
7
|
+
|
|
8
|
+
export declare function GridSelectionColumnBaseMixin<TItem, T extends Constructor<HTMLElement>>(
|
|
9
|
+
base: T,
|
|
10
|
+
): Constructor<GridSelectionColumnBaseMixinClass<TItem>> & T;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A mixin that provides basic functionality for the
|
|
14
|
+
* `<vaadin-grid-selection-column>`. This includes properties, cell rendering,
|
|
15
|
+
* and overridable methods for handling changes to the selection state.
|
|
16
|
+
*
|
|
17
|
+
* **NOTE**: This mixin is re-used by the Flow component, and as such must not
|
|
18
|
+
* implement any selection state updates for the column element or the grid.
|
|
19
|
+
* Web component-specific selection state updates must be implemented in the
|
|
20
|
+
* `<vaadin-grid-selection-column>` itself, by overriding the protected methods
|
|
21
|
+
* provided by this mixin.
|
|
22
|
+
*
|
|
23
|
+
* @polymerMixin
|
|
24
|
+
*/
|
|
25
|
+
export declare class GridSelectionColumnBaseMixinClass<TItem> {
|
|
26
|
+
/**
|
|
27
|
+
* When true, all the items are selected.
|
|
28
|
+
* @attr {boolean} select-all
|
|
29
|
+
*/
|
|
30
|
+
selectAll: boolean;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* When true, the active gets automatically selected.
|
|
34
|
+
* @attr {boolean} auto-select
|
|
35
|
+
*/
|
|
36
|
+
autoSelect: boolean;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Override to handle the user selecting all items.
|
|
40
|
+
*/
|
|
41
|
+
protected _selectAll(): void;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Override to handle the user deselecting all items.
|
|
45
|
+
*/
|
|
46
|
+
protected _deselectAll(): void;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Override to handle the user selecting an item.
|
|
50
|
+
*/
|
|
51
|
+
protected _selectItem(item: TItem): void;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Override to handle the user deselecting an item.
|
|
55
|
+
*/
|
|
56
|
+
protected _deselectItem(item: TItem): void;
|
|
57
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 - 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A mixin that provides basic functionality for the
|
|
9
|
+
* `<vaadin-grid-selection-column>`. This includes properties, cell rendering,
|
|
10
|
+
* and overridable methods for handling changes to the selection state.
|
|
11
|
+
*
|
|
12
|
+
* **NOTE**: This mixin is re-used by the Flow component, and as such must not
|
|
13
|
+
* implement any selection state updates for the column element or the grid.
|
|
14
|
+
* Web component-specific selection state updates must be implemented in the
|
|
15
|
+
* `<vaadin-grid-selection-column>` itself, by overriding the protected methods
|
|
16
|
+
* provided by this mixin.
|
|
17
|
+
*
|
|
18
|
+
* @polymerMixin
|
|
19
|
+
*/
|
|
20
|
+
export const GridSelectionColumnBaseMixin = (superClass) =>
|
|
21
|
+
class GridSelectionColumnBaseMixin extends superClass {
|
|
22
|
+
static get properties() {
|
|
23
|
+
return {
|
|
24
|
+
/**
|
|
25
|
+
* Width of the cells for this column.
|
|
26
|
+
*/
|
|
27
|
+
width: {
|
|
28
|
+
type: String,
|
|
29
|
+
value: '58px',
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Flex grow ratio for the cell widths. When set to 0, cell width is fixed.
|
|
34
|
+
* @attr {number} flex-grow
|
|
35
|
+
* @type {number}
|
|
36
|
+
*/
|
|
37
|
+
flexGrow: {
|
|
38
|
+
type: Number,
|
|
39
|
+
value: 0,
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* When true, all the items are selected.
|
|
44
|
+
* @attr {boolean} select-all
|
|
45
|
+
* @type {boolean}
|
|
46
|
+
*/
|
|
47
|
+
selectAll: {
|
|
48
|
+
type: Boolean,
|
|
49
|
+
value: false,
|
|
50
|
+
notify: true,
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* When true, the active gets automatically selected.
|
|
55
|
+
* @attr {boolean} auto-select
|
|
56
|
+
* @type {boolean}
|
|
57
|
+
*/
|
|
58
|
+
autoSelect: {
|
|
59
|
+
type: Boolean,
|
|
60
|
+
value: false,
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
/** @protected */
|
|
64
|
+
_indeterminate: Boolean,
|
|
65
|
+
|
|
66
|
+
/** @protected */
|
|
67
|
+
_selectAllHidden: Boolean,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static get observers() {
|
|
72
|
+
return [
|
|
73
|
+
'_onHeaderRendererOrBindingChanged(_headerRenderer, _headerCell, path, header, selectAll, _indeterminate, _selectAllHidden)',
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Renders the Select All checkbox to the header cell.
|
|
79
|
+
*
|
|
80
|
+
* @override
|
|
81
|
+
*/
|
|
82
|
+
_defaultHeaderRenderer(root, _column) {
|
|
83
|
+
let checkbox = root.firstElementChild;
|
|
84
|
+
if (!checkbox) {
|
|
85
|
+
checkbox = document.createElement('vaadin-checkbox');
|
|
86
|
+
checkbox.setAttribute('aria-label', 'Select All');
|
|
87
|
+
checkbox.classList.add('vaadin-grid-select-all-checkbox');
|
|
88
|
+
root.appendChild(checkbox);
|
|
89
|
+
// Add listener after appending, so we can skip the initial change event
|
|
90
|
+
checkbox.addEventListener('checked-changed', this.__onSelectAllCheckedChanged.bind(this));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const checked = this.__isChecked(this.selectAll, this._indeterminate);
|
|
94
|
+
checkbox.__rendererChecked = checked;
|
|
95
|
+
checkbox.checked = checked;
|
|
96
|
+
checkbox.hidden = this._selectAllHidden;
|
|
97
|
+
checkbox.indeterminate = this._indeterminate;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Renders the Select Row checkbox to the body cell.
|
|
102
|
+
*
|
|
103
|
+
* @override
|
|
104
|
+
*/
|
|
105
|
+
_defaultRenderer(root, _column, { item, selected }) {
|
|
106
|
+
let checkbox = root.firstElementChild;
|
|
107
|
+
if (!checkbox) {
|
|
108
|
+
checkbox = document.createElement('vaadin-checkbox');
|
|
109
|
+
checkbox.setAttribute('aria-label', 'Select Row');
|
|
110
|
+
root.appendChild(checkbox);
|
|
111
|
+
// Add listener after appending, so we can skip the initial change event
|
|
112
|
+
checkbox.addEventListener('checked-changed', this.__onSelectRowCheckedChanged.bind(this));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
checkbox.__item = item;
|
|
116
|
+
checkbox.__rendererChecked = selected;
|
|
117
|
+
checkbox.checked = selected;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Updates the select all state when the Select All checkbox is switched.
|
|
122
|
+
* The listener handles only user-fired events.
|
|
123
|
+
*
|
|
124
|
+
* @private
|
|
125
|
+
*/
|
|
126
|
+
__onSelectAllCheckedChanged(e) {
|
|
127
|
+
// Skip if the state is changed by the renderer.
|
|
128
|
+
if (e.target.checked === e.target.__rendererChecked) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (this._indeterminate || e.target.checked) {
|
|
133
|
+
this._selectAll();
|
|
134
|
+
} else {
|
|
135
|
+
this._deselectAll();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Selects or deselects the row when the Select Row checkbox is switched.
|
|
141
|
+
* The listener handles only user-fired events.
|
|
142
|
+
*
|
|
143
|
+
* @private
|
|
144
|
+
*/
|
|
145
|
+
__onSelectRowCheckedChanged(e) {
|
|
146
|
+
// Skip if the state is changed by the renderer.
|
|
147
|
+
if (e.target.checked === e.target.__rendererChecked) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (e.target.checked) {
|
|
152
|
+
this._selectItem(e.target.__item);
|
|
153
|
+
} else {
|
|
154
|
+
this._deselectItem(e.target.__item);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Override to handle the user selecting all items.
|
|
160
|
+
* @protected
|
|
161
|
+
*/
|
|
162
|
+
_selectAll() {}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Override to handle the user deselecting all items.
|
|
166
|
+
* @protected
|
|
167
|
+
*/
|
|
168
|
+
_deselectAll() {}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Override to handle the user selecting an item.
|
|
172
|
+
* @param {Object} item the item to select
|
|
173
|
+
* @protected
|
|
174
|
+
*/
|
|
175
|
+
_selectItem(item) {}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Override to handle the user deselecting an item.
|
|
179
|
+
* @param {Object} item the item to deselect
|
|
180
|
+
* @protected
|
|
181
|
+
*/
|
|
182
|
+
_deselectItem(item) {}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* IOS needs indeterminate + checked at the same time
|
|
186
|
+
* @private
|
|
187
|
+
*/
|
|
188
|
+
__isChecked(selectAll, indeterminate) {
|
|
189
|
+
return indeterminate || selectAll;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { GridDefaultItem } from './vaadin-grid.js';
|
|
7
7
|
import { GridColumn } from './vaadin-grid-column.js';
|
|
8
|
+
import type { GridSelectionColumnBaseMixinClass } from './vaadin-grid-selection-column-base-mixin.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Fired when the `selectAll` property changes.
|
|
@@ -42,18 +43,6 @@ export interface GridSelectionColumnEventMap extends HTMLElementEventMap, GridSe
|
|
|
42
43
|
* @fires {CustomEvent} select-all-changed - Fired when the `selectAll` property changes.
|
|
43
44
|
*/
|
|
44
45
|
declare class GridSelectionColumn<TItem = GridDefaultItem> extends GridColumn<TItem> {
|
|
45
|
-
/**
|
|
46
|
-
* When true, all the items are selected.
|
|
47
|
-
* @attr {boolean} select-all
|
|
48
|
-
*/
|
|
49
|
-
selectAll: boolean;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* When true, the active gets automatically selected.
|
|
53
|
-
* @attr {boolean} auto-select
|
|
54
|
-
*/
|
|
55
|
-
autoSelect: boolean;
|
|
56
|
-
|
|
57
46
|
addEventListener<K extends keyof GridSelectionColumnEventMap>(
|
|
58
47
|
type: K,
|
|
59
48
|
listener: (this: GridSelectionColumn<TItem>, ev: GridSelectionColumnEventMap[K]) => void,
|
|
@@ -67,6 +56,8 @@ declare class GridSelectionColumn<TItem = GridDefaultItem> extends GridColumn<TI
|
|
|
67
56
|
): void;
|
|
68
57
|
}
|
|
69
58
|
|
|
59
|
+
interface GridSelectionColumn<TItem = GridDefaultItem> extends GridSelectionColumnBaseMixinClass<TItem> {}
|
|
60
|
+
|
|
70
61
|
declare global {
|
|
71
62
|
interface HTMLElementTagNameMap {
|
|
72
63
|
'vaadin-grid-selection-column': GridSelectionColumn<GridDefaultItem>;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import '@vaadin/checkbox/src/vaadin-checkbox.js';
|
|
7
7
|
import { GridColumn } from './vaadin-grid-column.js';
|
|
8
|
+
import { GridSelectionColumnBaseMixin } from './vaadin-grid-selection-column-base-mixin.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* `<vaadin-grid-selection-column>` is a helper element for the `<vaadin-grid>`
|
|
@@ -28,74 +29,27 @@ import { GridColumn } from './vaadin-grid-column.js';
|
|
|
28
29
|
*
|
|
29
30
|
* __The default content can also be overridden__
|
|
30
31
|
*
|
|
32
|
+
* @mixes GridSelectionColumnBaseMixin
|
|
31
33
|
* @fires {CustomEvent} select-all-changed - Fired when the `selectAll` property changes.
|
|
32
34
|
*/
|
|
33
|
-
class GridSelectionColumn extends GridColumn {
|
|
35
|
+
class GridSelectionColumn extends GridSelectionColumnBaseMixin(GridColumn) {
|
|
34
36
|
static get is() {
|
|
35
37
|
return 'vaadin-grid-selection-column';
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
static get properties() {
|
|
39
41
|
return {
|
|
40
|
-
/**
|
|
41
|
-
* Width of the cells for this column.
|
|
42
|
-
*/
|
|
43
|
-
width: {
|
|
44
|
-
type: String,
|
|
45
|
-
value: '58px',
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Flex grow ratio for the cell widths. When set to 0, cell width is fixed.
|
|
50
|
-
* @attr {number} flex-grow
|
|
51
|
-
* @type {number}
|
|
52
|
-
*/
|
|
53
|
-
flexGrow: {
|
|
54
|
-
type: Number,
|
|
55
|
-
value: 0,
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* When true, all the items are selected.
|
|
60
|
-
* @attr {boolean} select-all
|
|
61
|
-
* @type {boolean}
|
|
62
|
-
*/
|
|
63
|
-
selectAll: {
|
|
64
|
-
type: Boolean,
|
|
65
|
-
value: false,
|
|
66
|
-
notify: true,
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* When true, the active gets automatically selected.
|
|
71
|
-
* @attr {boolean} auto-select
|
|
72
|
-
* @type {boolean}
|
|
73
|
-
*/
|
|
74
|
-
autoSelect: {
|
|
75
|
-
type: Boolean,
|
|
76
|
-
value: false,
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
/** @private */
|
|
80
|
-
__indeterminate: Boolean,
|
|
81
|
-
|
|
82
42
|
/**
|
|
83
43
|
* The previous state of activeItem. When activeItem turns to `null`,
|
|
84
44
|
* previousActiveItem will have an Object with just unselected activeItem
|
|
85
45
|
* @private
|
|
86
46
|
*/
|
|
87
47
|
__previousActiveItem: Object,
|
|
88
|
-
|
|
89
|
-
/** @private */
|
|
90
|
-
__selectAllHidden: Boolean,
|
|
91
48
|
};
|
|
92
49
|
}
|
|
93
50
|
|
|
94
51
|
static get observers() {
|
|
95
|
-
return [
|
|
96
|
-
'__onSelectAllChanged(selectAll)',
|
|
97
|
-
'_onHeaderRendererOrBindingChanged(_headerRenderer, _headerCell, path, header, selectAll, __indeterminate, __selectAllHidden)',
|
|
98
|
-
];
|
|
52
|
+
return ['__onSelectAllChanged(selectAll)'];
|
|
99
53
|
}
|
|
100
54
|
|
|
101
55
|
constructor() {
|
|
@@ -127,47 +81,6 @@ class GridSelectionColumn extends GridColumn {
|
|
|
127
81
|
}
|
|
128
82
|
}
|
|
129
83
|
|
|
130
|
-
/**
|
|
131
|
-
* Renders the Select All checkbox to the header cell.
|
|
132
|
-
*
|
|
133
|
-
* @override
|
|
134
|
-
*/
|
|
135
|
-
_defaultHeaderRenderer(root, _column) {
|
|
136
|
-
let checkbox = root.firstElementChild;
|
|
137
|
-
if (!checkbox) {
|
|
138
|
-
checkbox = document.createElement('vaadin-checkbox');
|
|
139
|
-
checkbox.setAttribute('aria-label', 'Select All');
|
|
140
|
-
checkbox.classList.add('vaadin-grid-select-all-checkbox');
|
|
141
|
-
checkbox.addEventListener('checked-changed', this.__onSelectAllCheckedChanged.bind(this));
|
|
142
|
-
root.appendChild(checkbox);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const checked = this.__isChecked(this.selectAll, this.__indeterminate);
|
|
146
|
-
checkbox.__rendererChecked = checked;
|
|
147
|
-
checkbox.checked = checked;
|
|
148
|
-
checkbox.hidden = this.__selectAllHidden;
|
|
149
|
-
checkbox.indeterminate = this.__indeterminate;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Renders the Select Row checkbox to the body cell.
|
|
154
|
-
*
|
|
155
|
-
* @override
|
|
156
|
-
*/
|
|
157
|
-
_defaultRenderer(root, _column, { item, selected }) {
|
|
158
|
-
let checkbox = root.firstElementChild;
|
|
159
|
-
if (!checkbox) {
|
|
160
|
-
checkbox = document.createElement('vaadin-checkbox');
|
|
161
|
-
checkbox.setAttribute('aria-label', 'Select Row');
|
|
162
|
-
checkbox.addEventListener('checked-changed', this.__onSelectRowCheckedChanged.bind(this));
|
|
163
|
-
root.appendChild(checkbox);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
checkbox.__item = item;
|
|
167
|
-
checkbox.__rendererChecked = selected;
|
|
168
|
-
checkbox.checked = selected;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
84
|
/** @private */
|
|
172
85
|
__onSelectAllChanged(selectAll) {
|
|
173
86
|
if (selectAll === undefined || !this._grid) {
|
|
@@ -203,45 +116,49 @@ class GridSelectionColumn extends GridColumn {
|
|
|
203
116
|
}
|
|
204
117
|
|
|
205
118
|
/**
|
|
206
|
-
*
|
|
207
|
-
*
|
|
119
|
+
* Override a method from `GridSelectionColumnBaseMixin` to handle the user
|
|
120
|
+
* selecting all items.
|
|
208
121
|
*
|
|
209
|
-
* @
|
|
122
|
+
* @protected
|
|
123
|
+
* @override
|
|
210
124
|
*/
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (e.target.checked === e.target.__rendererChecked) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
this.selectAll = this.__indeterminate || e.target.checked;
|
|
125
|
+
_selectAll() {
|
|
126
|
+
this.selectAll = true;
|
|
218
127
|
}
|
|
219
128
|
|
|
220
129
|
/**
|
|
221
|
-
*
|
|
222
|
-
*
|
|
130
|
+
* Override a method from `GridSelectionColumnBaseMixin` to handle the user
|
|
131
|
+
* deselecting all items.
|
|
223
132
|
*
|
|
224
|
-
* @
|
|
133
|
+
* @protected
|
|
134
|
+
* @override
|
|
225
135
|
*/
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
136
|
+
_deselectAll() {
|
|
137
|
+
this.selectAll = false;
|
|
138
|
+
}
|
|
231
139
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Override a method from `GridSelectionColumnBaseMixin` to handle the user
|
|
142
|
+
* selecting an item.
|
|
143
|
+
*
|
|
144
|
+
* @param {Object} item the item to select
|
|
145
|
+
* @protected
|
|
146
|
+
* @override
|
|
147
|
+
*/
|
|
148
|
+
_selectItem(item) {
|
|
149
|
+
this._grid.selectItem(item);
|
|
237
150
|
}
|
|
238
151
|
|
|
239
152
|
/**
|
|
240
|
-
*
|
|
241
|
-
*
|
|
153
|
+
* Override a method from `GridSelectionColumnBaseMixin` to handle the user
|
|
154
|
+
* deselecting an item.
|
|
155
|
+
*
|
|
156
|
+
* @param {Object} item the item to deselect
|
|
157
|
+
* @protected
|
|
158
|
+
* @override
|
|
242
159
|
*/
|
|
243
|
-
|
|
244
|
-
|
|
160
|
+
_deselectItem(item) {
|
|
161
|
+
this._grid.deselectItem(item);
|
|
245
162
|
}
|
|
246
163
|
|
|
247
164
|
/** @private */
|
|
@@ -268,13 +185,13 @@ class GridSelectionColumn extends GridColumn {
|
|
|
268
185
|
this.__withFilteredItemsArray((items) => {
|
|
269
186
|
if (!this._grid.selectedItems.length) {
|
|
270
187
|
this.selectAll = false;
|
|
271
|
-
this.
|
|
188
|
+
this._indeterminate = false;
|
|
272
189
|
} else if (this.__arrayContains(this._grid.selectedItems, items)) {
|
|
273
190
|
this.selectAll = true;
|
|
274
|
-
this.
|
|
191
|
+
this._indeterminate = false;
|
|
275
192
|
} else {
|
|
276
193
|
this.selectAll = false;
|
|
277
|
-
this.
|
|
194
|
+
this._indeterminate = true;
|
|
278
195
|
}
|
|
279
196
|
});
|
|
280
197
|
}
|
|
@@ -283,7 +200,7 @@ class GridSelectionColumn extends GridColumn {
|
|
|
283
200
|
|
|
284
201
|
/** @private */
|
|
285
202
|
__onDataProviderChanged() {
|
|
286
|
-
this.
|
|
203
|
+
this._selectAllHidden = !Array.isArray(this._grid.items);
|
|
287
204
|
}
|
|
288
205
|
|
|
289
206
|
/**
|