@vaadin/grid 24.2.3 → 24.3.0-alpha10
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 +18 -13
- package/src/vaadin-grid-a11y-mixin.js +1 -1
- package/src/vaadin-grid-active-item-mixin.js +1 -0
- package/src/vaadin-grid-array-data-provider-mixin.js +14 -17
- package/src/vaadin-grid-column-group-mixin.d.ts +20 -0
- package/src/vaadin-grid-column-group-mixin.js +364 -0
- package/src/vaadin-grid-column-group.d.ts +4 -14
- package/src/vaadin-grid-column-group.js +5 -355
- package/src/vaadin-grid-column-mixin.d.ts +170 -0
- package/src/vaadin-grid-column-mixin.js +958 -0
- package/src/vaadin-grid-column.d.ts +11 -138
- package/src/vaadin-grid-column.js +5 -876
- package/src/vaadin-grid-data-provider-mixin.d.ts +6 -30
- package/src/vaadin-grid-data-provider-mixin.js +122 -246
- package/src/vaadin-grid-drag-and-drop-mixin.js +17 -5
- package/src/vaadin-grid-dynamic-columns-mixin.js +22 -17
- package/src/vaadin-grid-filter-column-mixin.d.ts +22 -0
- package/src/vaadin-grid-filter-column-mixin.js +106 -0
- package/src/vaadin-grid-filter-column.d.ts +9 -11
- package/src/vaadin-grid-filter-column.js +3 -90
- package/src/vaadin-grid-filter-element-mixin.d.ts +34 -0
- package/src/vaadin-grid-filter-element-mixin.js +108 -0
- package/src/vaadin-grid-filter-mixin.js +4 -4
- package/src/vaadin-grid-filter.d.ts +4 -21
- package/src/vaadin-grid-filter.js +5 -84
- package/src/vaadin-grid-helpers.js +94 -0
- package/src/vaadin-grid-keyboard-navigation-mixin.js +11 -4
- package/src/vaadin-grid-mixin.js +21 -37
- package/src/vaadin-grid-row-details-mixin.js +7 -8
- package/src/vaadin-grid-scroll-mixin.js +2 -1
- package/src/vaadin-grid-selection-column-base-mixin.js +12 -4
- package/src/vaadin-grid-selection-column-mixin.d.ts +24 -0
- package/src/vaadin-grid-selection-column-mixin.js +194 -0
- package/src/vaadin-grid-selection-column.d.ts +13 -17
- package/src/vaadin-grid-selection-column.js +4 -186
- package/src/vaadin-grid-selection-mixin.js +4 -3
- package/src/vaadin-grid-sort-column-mixin.d.ts +36 -0
- package/src/vaadin-grid-sort-column-mixin.js +101 -0
- package/src/vaadin-grid-sort-column.d.ts +8 -26
- package/src/vaadin-grid-sort-column.js +3 -87
- package/src/vaadin-grid-sorter-mixin.d.ts +44 -0
- package/src/vaadin-grid-sorter-mixin.js +200 -0
- package/src/vaadin-grid-sorter.d.ts +3 -32
- package/src/vaadin-grid-sorter.js +5 -181
- package/src/vaadin-grid-styles.js +341 -345
- package/src/vaadin-grid-styling-mixin.js +8 -2
- package/src/vaadin-grid-tree-column-mixin.d.ts +18 -0
- package/src/vaadin-grid-tree-column-mixin.js +99 -0
- package/src/vaadin-grid-tree-column.d.ts +9 -7
- package/src/vaadin-grid-tree-column.js +3 -82
- package/src/vaadin-grid-tree-toggle-mixin.d.ts +39 -0
- package/src/vaadin-grid-tree-toggle-mixin.js +153 -0
- package/src/vaadin-grid-tree-toggle.d.ts +4 -27
- package/src/vaadin-grid-tree-toggle.js +9 -141
- package/src/vaadin-grid.d.ts +3 -0
- package/src/vaadin-grid.js +7 -2
- package/theme/lumo/vaadin-grid-sorter-styles.js +1 -1
- package/theme/lumo/vaadin-grid-styles.js +15 -14
- package/theme/material/vaadin-grid-styles.js +15 -10
- package/web-types.json +331 -126
- package/web-types.lit.json +114 -58
|
@@ -0,0 +1,194 @@
|
|
|
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 { GridSelectionColumnBaseMixin } from './vaadin-grid-selection-column-base-mixin.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @polymerMixin
|
|
10
|
+
*/
|
|
11
|
+
export const GridSelectionColumnMixin = (superClass) =>
|
|
12
|
+
class extends GridSelectionColumnBaseMixin(superClass) {
|
|
13
|
+
static get properties() {
|
|
14
|
+
return {
|
|
15
|
+
/**
|
|
16
|
+
* The previous state of activeItem. When activeItem turns to `null`,
|
|
17
|
+
* previousActiveItem will have an Object with just unselected activeItem
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
__previousActiveItem: Object,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static get observers() {
|
|
25
|
+
return ['__onSelectAllChanged(selectAll)'];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
constructor() {
|
|
29
|
+
super();
|
|
30
|
+
|
|
31
|
+
this.__boundOnActiveItemChanged = this.__onActiveItemChanged.bind(this);
|
|
32
|
+
this.__boundOnDataProviderChanged = this.__onDataProviderChanged.bind(this);
|
|
33
|
+
this.__boundOnSelectedItemsChanged = this.__onSelectedItemsChanged.bind(this);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** @protected */
|
|
37
|
+
disconnectedCallback() {
|
|
38
|
+
this._grid.removeEventListener('active-item-changed', this.__boundOnActiveItemChanged);
|
|
39
|
+
this._grid.removeEventListener('data-provider-changed', this.__boundOnDataProviderChanged);
|
|
40
|
+
this._grid.removeEventListener('filter-changed', this.__boundOnSelectedItemsChanged);
|
|
41
|
+
this._grid.removeEventListener('selected-items-changed', this.__boundOnSelectedItemsChanged);
|
|
42
|
+
|
|
43
|
+
super.disconnectedCallback();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @protected */
|
|
47
|
+
connectedCallback() {
|
|
48
|
+
super.connectedCallback();
|
|
49
|
+
if (this._grid) {
|
|
50
|
+
this._grid.addEventListener('active-item-changed', this.__boundOnActiveItemChanged);
|
|
51
|
+
this._grid.addEventListener('data-provider-changed', this.__boundOnDataProviderChanged);
|
|
52
|
+
this._grid.addEventListener('filter-changed', this.__boundOnSelectedItemsChanged);
|
|
53
|
+
this._grid.addEventListener('selected-items-changed', this.__boundOnSelectedItemsChanged);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @private */
|
|
58
|
+
__onSelectAllChanged(selectAll) {
|
|
59
|
+
if (selectAll === undefined || !this._grid) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!this.__selectAllInitialized) {
|
|
64
|
+
// The initial value for selectAll property was applied, avoid clearing pre-selected items
|
|
65
|
+
this.__selectAllInitialized = true;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (this._selectAllChangeLock) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (selectAll && this.__hasArrayDataProvider()) {
|
|
74
|
+
this.__withFilteredItemsArray((items) => {
|
|
75
|
+
this._grid.selectedItems = items;
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
this._grid.selectedItems = [];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Return true if array `a` contains all the items in `b`
|
|
84
|
+
* We need this when sorting or to preserve selection after filtering.
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
__arrayContains(a, b) {
|
|
88
|
+
return Array.isArray(a) && Array.isArray(b) && b.every((i) => a.includes(i));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Override a method from `GridSelectionColumnBaseMixin` to handle the user
|
|
93
|
+
* selecting all items.
|
|
94
|
+
*
|
|
95
|
+
* @protected
|
|
96
|
+
* @override
|
|
97
|
+
*/
|
|
98
|
+
_selectAll() {
|
|
99
|
+
this.selectAll = true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Override a method from `GridSelectionColumnBaseMixin` to handle the user
|
|
104
|
+
* deselecting all items.
|
|
105
|
+
*
|
|
106
|
+
* @protected
|
|
107
|
+
* @override
|
|
108
|
+
*/
|
|
109
|
+
_deselectAll() {
|
|
110
|
+
this.selectAll = false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Override a method from `GridSelectionColumnBaseMixin` to handle the user
|
|
115
|
+
* selecting an item.
|
|
116
|
+
*
|
|
117
|
+
* @param {Object} item the item to select
|
|
118
|
+
* @protected
|
|
119
|
+
* @override
|
|
120
|
+
*/
|
|
121
|
+
_selectItem(item) {
|
|
122
|
+
this._grid.selectItem(item);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Override a method from `GridSelectionColumnBaseMixin` to handle the user
|
|
127
|
+
* deselecting an item.
|
|
128
|
+
*
|
|
129
|
+
* @param {Object} item the item to deselect
|
|
130
|
+
* @protected
|
|
131
|
+
* @override
|
|
132
|
+
*/
|
|
133
|
+
_deselectItem(item) {
|
|
134
|
+
this._grid.deselectItem(item);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** @private */
|
|
138
|
+
__onActiveItemChanged(e) {
|
|
139
|
+
const activeItem = e.detail.value;
|
|
140
|
+
if (this.autoSelect) {
|
|
141
|
+
const item = activeItem || this.__previousActiveItem;
|
|
142
|
+
if (item) {
|
|
143
|
+
this._grid._toggleItem(item);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
this.__previousActiveItem = activeItem;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** @private */
|
|
150
|
+
__hasArrayDataProvider() {
|
|
151
|
+
return Array.isArray(this._grid.items) && !!this._grid.dataProvider;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** @private */
|
|
155
|
+
__onSelectedItemsChanged() {
|
|
156
|
+
this._selectAllChangeLock = true;
|
|
157
|
+
if (this.__hasArrayDataProvider()) {
|
|
158
|
+
this.__withFilteredItemsArray((items) => {
|
|
159
|
+
if (!this._grid.selectedItems.length) {
|
|
160
|
+
this.selectAll = false;
|
|
161
|
+
this._indeterminate = false;
|
|
162
|
+
} else if (this.__arrayContains(this._grid.selectedItems, items)) {
|
|
163
|
+
this.selectAll = true;
|
|
164
|
+
this._indeterminate = false;
|
|
165
|
+
} else {
|
|
166
|
+
this.selectAll = false;
|
|
167
|
+
this._indeterminate = true;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
this._selectAllChangeLock = false;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** @private */
|
|
175
|
+
__onDataProviderChanged() {
|
|
176
|
+
this._selectAllHidden = !Array.isArray(this._grid.items);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Assuming the grid uses an items array data provider, fetches all the filtered items
|
|
181
|
+
* from the data provider and invokes the callback with the resulting array.
|
|
182
|
+
*
|
|
183
|
+
* @private
|
|
184
|
+
*/
|
|
185
|
+
__withFilteredItemsArray(callback) {
|
|
186
|
+
const params = {
|
|
187
|
+
page: 0,
|
|
188
|
+
pageSize: Infinity,
|
|
189
|
+
sortOrders: [],
|
|
190
|
+
filters: this._grid._mapFilters(),
|
|
191
|
+
};
|
|
192
|
+
this._grid.dataProvider(params, (items) => callback(items));
|
|
193
|
+
}
|
|
194
|
+
};
|
|
@@ -4,19 +4,14 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import type { GridDefaultItem } from './vaadin-grid.js';
|
|
7
|
-
import {
|
|
8
|
-
import type {
|
|
7
|
+
import type { GridColumnMixin } from './vaadin-grid-column.js';
|
|
8
|
+
import type { GridColumn } from './vaadin-grid-column.js';
|
|
9
|
+
import type {
|
|
10
|
+
GridSelectionColumnEventMap,
|
|
11
|
+
GridSelectionColumnMixinClass,
|
|
12
|
+
} from './vaadin-grid-selection-column-mixin.js';
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
* Fired when the `selectAll` property changes.
|
|
12
|
-
*/
|
|
13
|
-
export type GridSelectionColumnSelectAllChangedEvent = CustomEvent<{ value: boolean }>;
|
|
14
|
-
|
|
15
|
-
export interface GridSelectionColumnCustomEventMap {
|
|
16
|
-
'select-all-changed': GridSelectionColumnSelectAllChangedEvent;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface GridSelectionColumnEventMap extends HTMLElementEventMap, GridSelectionColumnCustomEventMap {}
|
|
14
|
+
export * from './vaadin-grid-selection-column-mixin.js';
|
|
20
15
|
|
|
21
16
|
/**
|
|
22
17
|
* `<vaadin-grid-selection-column>` is a helper element for the `<vaadin-grid>`
|
|
@@ -39,10 +34,13 @@ export interface GridSelectionColumnEventMap extends HTMLElementEventMap, GridSe
|
|
|
39
34
|
* selection for all the items at once.
|
|
40
35
|
*
|
|
41
36
|
* __The default content can also be overridden__
|
|
42
|
-
*
|
|
43
|
-
* @fires {CustomEvent} select-all-changed - Fired when the `selectAll` property changes.
|
|
44
37
|
*/
|
|
45
|
-
declare class GridSelectionColumn<TItem = GridDefaultItem> extends
|
|
38
|
+
declare class GridSelectionColumn<TItem = GridDefaultItem> extends HTMLElement {}
|
|
39
|
+
|
|
40
|
+
interface GridSelectionColumn<TItem = GridDefaultItem>
|
|
41
|
+
extends GridSelectionColumnMixinClass<TItem>,
|
|
42
|
+
GridColumnMixin<TItem, GridColumn<TItem>>,
|
|
43
|
+
GridColumn<TItem> {
|
|
46
44
|
addEventListener<K extends keyof GridSelectionColumnEventMap>(
|
|
47
45
|
type: K,
|
|
48
46
|
listener: (this: GridSelectionColumn<TItem>, ev: GridSelectionColumnEventMap[K]) => void,
|
|
@@ -56,8 +54,6 @@ declare class GridSelectionColumn<TItem = GridDefaultItem> extends GridColumn<TI
|
|
|
56
54
|
): void;
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
interface GridSelectionColumn<TItem = GridDefaultItem> extends GridSelectionColumnBaseMixinClass<TItem> {}
|
|
60
|
-
|
|
61
57
|
declare global {
|
|
62
58
|
interface HTMLElementTagNameMap {
|
|
63
59
|
'vaadin-grid-selection-column': GridSelectionColumn<GridDefaultItem>;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import '@vaadin/checkbox/src/vaadin-checkbox.js';
|
|
7
7
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
8
8
|
import { GridColumn } from './vaadin-grid-column.js';
|
|
9
|
-
import {
|
|
9
|
+
import { GridSelectionColumnMixin } from './vaadin-grid-selection-column-mixin.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* `<vaadin-grid-selection-column>` is a helper element for the `<vaadin-grid>`
|
|
@@ -31,196 +31,14 @@ import { GridSelectionColumnBaseMixin } from './vaadin-grid-selection-column-bas
|
|
|
31
31
|
* __The default content can also be overridden__
|
|
32
32
|
*
|
|
33
33
|
* @customElement
|
|
34
|
-
* @extends GridColumn
|
|
35
|
-
* @mixes GridSelectionColumnBaseMixin
|
|
36
34
|
* @fires {CustomEvent} select-all-changed - Fired when the `selectAll` property changes.
|
|
35
|
+
* @extends GridColumn
|
|
36
|
+
* @mixes GridSelectionColumnMixin
|
|
37
37
|
*/
|
|
38
|
-
class GridSelectionColumn extends
|
|
38
|
+
class GridSelectionColumn extends GridSelectionColumnMixin(GridColumn) {
|
|
39
39
|
static get is() {
|
|
40
40
|
return 'vaadin-grid-selection-column';
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
static get properties() {
|
|
44
|
-
return {
|
|
45
|
-
/**
|
|
46
|
-
* The previous state of activeItem. When activeItem turns to `null`,
|
|
47
|
-
* previousActiveItem will have an Object with just unselected activeItem
|
|
48
|
-
* @private
|
|
49
|
-
*/
|
|
50
|
-
__previousActiveItem: Object,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
static get observers() {
|
|
55
|
-
return ['__onSelectAllChanged(selectAll)'];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
constructor() {
|
|
59
|
-
super();
|
|
60
|
-
|
|
61
|
-
this.__boundOnActiveItemChanged = this.__onActiveItemChanged.bind(this);
|
|
62
|
-
this.__boundOnDataProviderChanged = this.__onDataProviderChanged.bind(this);
|
|
63
|
-
this.__boundOnSelectedItemsChanged = this.__onSelectedItemsChanged.bind(this);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** @protected */
|
|
67
|
-
disconnectedCallback() {
|
|
68
|
-
this._grid.removeEventListener('active-item-changed', this.__boundOnActiveItemChanged);
|
|
69
|
-
this._grid.removeEventListener('data-provider-changed', this.__boundOnDataProviderChanged);
|
|
70
|
-
this._grid.removeEventListener('filter-changed', this.__boundOnSelectedItemsChanged);
|
|
71
|
-
this._grid.removeEventListener('selected-items-changed', this.__boundOnSelectedItemsChanged);
|
|
72
|
-
|
|
73
|
-
super.disconnectedCallback();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** @protected */
|
|
77
|
-
connectedCallback() {
|
|
78
|
-
super.connectedCallback();
|
|
79
|
-
if (this._grid) {
|
|
80
|
-
this._grid.addEventListener('active-item-changed', this.__boundOnActiveItemChanged);
|
|
81
|
-
this._grid.addEventListener('data-provider-changed', this.__boundOnDataProviderChanged);
|
|
82
|
-
this._grid.addEventListener('filter-changed', this.__boundOnSelectedItemsChanged);
|
|
83
|
-
this._grid.addEventListener('selected-items-changed', this.__boundOnSelectedItemsChanged);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** @private */
|
|
88
|
-
__onSelectAllChanged(selectAll) {
|
|
89
|
-
if (selectAll === undefined || !this._grid) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (!this.__selectAllInitialized) {
|
|
94
|
-
// The initial value for selectAll property was applied, avoid clearing pre-selected items
|
|
95
|
-
this.__selectAllInitialized = true;
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (this._selectAllChangeLock) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (selectAll && this.__hasArrayDataProvider()) {
|
|
104
|
-
this.__withFilteredItemsArray((items) => {
|
|
105
|
-
this._grid.selectedItems = items;
|
|
106
|
-
});
|
|
107
|
-
} else {
|
|
108
|
-
this._grid.selectedItems = [];
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Return true if array `a` contains all the items in `b`
|
|
114
|
-
* We need this when sorting or to preserve selection after filtering.
|
|
115
|
-
* @private
|
|
116
|
-
*/
|
|
117
|
-
__arrayContains(a, b) {
|
|
118
|
-
return Array.isArray(a) && Array.isArray(b) && b.every((i) => a.includes(i));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Override a method from `GridSelectionColumnBaseMixin` to handle the user
|
|
123
|
-
* selecting all items.
|
|
124
|
-
*
|
|
125
|
-
* @protected
|
|
126
|
-
* @override
|
|
127
|
-
*/
|
|
128
|
-
_selectAll() {
|
|
129
|
-
this.selectAll = true;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Override a method from `GridSelectionColumnBaseMixin` to handle the user
|
|
134
|
-
* deselecting all items.
|
|
135
|
-
*
|
|
136
|
-
* @protected
|
|
137
|
-
* @override
|
|
138
|
-
*/
|
|
139
|
-
_deselectAll() {
|
|
140
|
-
this.selectAll = false;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Override a method from `GridSelectionColumnBaseMixin` to handle the user
|
|
145
|
-
* selecting an item.
|
|
146
|
-
*
|
|
147
|
-
* @param {Object} item the item to select
|
|
148
|
-
* @protected
|
|
149
|
-
* @override
|
|
150
|
-
*/
|
|
151
|
-
_selectItem(item) {
|
|
152
|
-
this._grid.selectItem(item);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Override a method from `GridSelectionColumnBaseMixin` to handle the user
|
|
157
|
-
* deselecting an item.
|
|
158
|
-
*
|
|
159
|
-
* @param {Object} item the item to deselect
|
|
160
|
-
* @protected
|
|
161
|
-
* @override
|
|
162
|
-
*/
|
|
163
|
-
_deselectItem(item) {
|
|
164
|
-
this._grid.deselectItem(item);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/** @private */
|
|
168
|
-
__onActiveItemChanged(e) {
|
|
169
|
-
const activeItem = e.detail.value;
|
|
170
|
-
if (this.autoSelect) {
|
|
171
|
-
const item = activeItem || this.__previousActiveItem;
|
|
172
|
-
if (item) {
|
|
173
|
-
this._grid._toggleItem(item);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
this.__previousActiveItem = activeItem;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/** @private */
|
|
180
|
-
__hasArrayDataProvider() {
|
|
181
|
-
return Array.isArray(this._grid.items) && !!this._grid.dataProvider;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/** @private */
|
|
185
|
-
__onSelectedItemsChanged() {
|
|
186
|
-
this._selectAllChangeLock = true;
|
|
187
|
-
if (this.__hasArrayDataProvider()) {
|
|
188
|
-
this.__withFilteredItemsArray((items) => {
|
|
189
|
-
if (!this._grid.selectedItems.length) {
|
|
190
|
-
this.selectAll = false;
|
|
191
|
-
this._indeterminate = false;
|
|
192
|
-
} else if (this.__arrayContains(this._grid.selectedItems, items)) {
|
|
193
|
-
this.selectAll = true;
|
|
194
|
-
this._indeterminate = false;
|
|
195
|
-
} else {
|
|
196
|
-
this.selectAll = false;
|
|
197
|
-
this._indeterminate = true;
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
this._selectAllChangeLock = false;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/** @private */
|
|
205
|
-
__onDataProviderChanged() {
|
|
206
|
-
this._selectAllHidden = !Array.isArray(this._grid.items);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Assuming the grid uses an items array data provider, fetches all the filtered items
|
|
211
|
-
* from the data provider and invokes the callback with the resulting array.
|
|
212
|
-
*
|
|
213
|
-
* @private
|
|
214
|
-
*/
|
|
215
|
-
__withFilteredItemsArray(callback) {
|
|
216
|
-
const params = {
|
|
217
|
-
page: 0,
|
|
218
|
-
pageSize: Infinity,
|
|
219
|
-
sortOrders: [],
|
|
220
|
-
filters: this._grid._mapFilters(),
|
|
221
|
-
};
|
|
222
|
-
this._grid.dataProvider(params, (items) => callback(items));
|
|
223
|
-
}
|
|
224
42
|
}
|
|
225
43
|
|
|
226
44
|
defineCustomElement(GridSelectionColumn);
|
|
@@ -19,6 +19,7 @@ export const SelectionMixin = (superClass) =>
|
|
|
19
19
|
type: Object,
|
|
20
20
|
notify: true,
|
|
21
21
|
value: () => [],
|
|
22
|
+
sync: true,
|
|
22
23
|
},
|
|
23
24
|
|
|
24
25
|
/**
|
|
@@ -27,13 +28,13 @@ export const SelectionMixin = (superClass) =>
|
|
|
27
28
|
*/
|
|
28
29
|
__selectedKeys: {
|
|
29
30
|
type: Object,
|
|
30
|
-
computed: '__computeSelectedKeys(itemIdPath, selectedItems
|
|
31
|
+
computed: '__computeSelectedKeys(itemIdPath, selectedItems)',
|
|
31
32
|
},
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
static get observers() {
|
|
36
|
-
return ['__selectedItemsChanged(itemIdPath, selectedItems
|
|
37
|
+
return ['__selectedItemsChanged(itemIdPath, selectedItems)'];
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
/**
|
|
@@ -91,7 +92,7 @@ export const SelectionMixin = (superClass) =>
|
|
|
91
92
|
|
|
92
93
|
/** @private */
|
|
93
94
|
__computeSelectedKeys(itemIdPath, selectedItems) {
|
|
94
|
-
const selected = selectedItems
|
|
95
|
+
const selected = selectedItems || [];
|
|
95
96
|
const selectedKeys = new Set();
|
|
96
97
|
selected.forEach((item) => {
|
|
97
98
|
selectedKeys.add(this.getItemId(item));
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
import type { GridSorterDirection } from './vaadin-grid-sorter.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Fired when the `direction` property changes.
|
|
11
|
+
*/
|
|
12
|
+
export type GridSortColumnDirectionChangedEvent = CustomEvent<{ value: GridSorterDirection }>;
|
|
13
|
+
|
|
14
|
+
export interface GridSortColumnCustomEventMap {
|
|
15
|
+
'direction-changed': GridSortColumnDirectionChangedEvent;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface GridSortColumnEventMap extends HTMLElementEventMap, GridSortColumnCustomEventMap {}
|
|
19
|
+
|
|
20
|
+
export declare function GridSortColumnMixin<T extends Constructor<HTMLElement>>(
|
|
21
|
+
superclass: T,
|
|
22
|
+
): Constructor<GridSortColumnMixinClass> & T;
|
|
23
|
+
|
|
24
|
+
export declare class GridSortColumnMixinClass {
|
|
25
|
+
/**
|
|
26
|
+
* JS Path of the property in the item used for sorting the data.
|
|
27
|
+
*/
|
|
28
|
+
path: string | null | undefined;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* How to sort the data.
|
|
32
|
+
* Possible values are `asc` to use an ascending algorithm, `desc` to sort the data in
|
|
33
|
+
* descending direction, or `null` for not sorting the data.
|
|
34
|
+
*/
|
|
35
|
+
direction: GridSorterDirection | null | undefined;
|
|
36
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
* @polymerMixin
|
|
9
|
+
*/
|
|
10
|
+
export const GridSortColumnMixin = (superClass) =>
|
|
11
|
+
class extends superClass {
|
|
12
|
+
static get properties() {
|
|
13
|
+
return {
|
|
14
|
+
/**
|
|
15
|
+
* JS Path of the property in the item used for sorting the data.
|
|
16
|
+
*/
|
|
17
|
+
path: {
|
|
18
|
+
type: String,
|
|
19
|
+
sync: true,
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* How to sort the data.
|
|
24
|
+
* Possible values are `asc` to use an ascending algorithm, `desc` to sort the data in
|
|
25
|
+
* descending direction, or `null` for not sorting the data.
|
|
26
|
+
* @type {GridSorterDirection | undefined}
|
|
27
|
+
*/
|
|
28
|
+
direction: {
|
|
29
|
+
type: String,
|
|
30
|
+
notify: true,
|
|
31
|
+
sync: true,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static get observers() {
|
|
37
|
+
return ['_onHeaderRendererOrBindingChanged(_headerRenderer, _headerCell, path, header, direction)'];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
constructor() {
|
|
41
|
+
super();
|
|
42
|
+
|
|
43
|
+
this.__boundOnDirectionChanged = this.__onDirectionChanged.bind(this);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Renders the grid sorter to the header cell.
|
|
48
|
+
*
|
|
49
|
+
* @override
|
|
50
|
+
*/
|
|
51
|
+
_defaultHeaderRenderer(root, _column) {
|
|
52
|
+
let sorter = root.firstElementChild;
|
|
53
|
+
if (!sorter) {
|
|
54
|
+
sorter = document.createElement('vaadin-grid-sorter');
|
|
55
|
+
sorter.addEventListener('direction-changed', this.__boundOnDirectionChanged);
|
|
56
|
+
root.appendChild(sorter);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
sorter.path = this.path;
|
|
60
|
+
sorter.__rendererDirection = this.direction;
|
|
61
|
+
sorter.direction = this.direction;
|
|
62
|
+
sorter.textContent = this.__getHeader(this.header, this.path);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The sort column doesn't allow to use a custom header renderer
|
|
67
|
+
* to override the header cell content.
|
|
68
|
+
* It always renders the grid sorter to the header cell.
|
|
69
|
+
*
|
|
70
|
+
* @override
|
|
71
|
+
*/
|
|
72
|
+
_computeHeaderRenderer() {
|
|
73
|
+
return this._defaultHeaderRenderer;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Updates the sorting direction once the grid sorter's direction is changed.
|
|
78
|
+
* The listener handles only user-fired events.
|
|
79
|
+
*
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
__onDirectionChanged(e) {
|
|
83
|
+
// Skip if the direction is changed by the renderer.
|
|
84
|
+
if (e.detail.value === e.target.__rendererDirection) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
this.direction = e.detail.value;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** @private */
|
|
92
|
+
__getHeader(header, path) {
|
|
93
|
+
if (header) {
|
|
94
|
+
return header;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (path) {
|
|
98
|
+
return this._generateHeader(path);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
@@ -4,19 +4,10 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import type { GridDefaultItem } from './vaadin-grid.js';
|
|
7
|
-
import { GridColumn } from './vaadin-grid-column.js';
|
|
8
|
-
import type {
|
|
7
|
+
import type { GridColumn, GridColumnMixin } from './vaadin-grid-column.js';
|
|
8
|
+
import type { GridSortColumnEventMap, GridSortColumnMixinClass } from './vaadin-grid-sort-column-mixin.js';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
* Fired when the `direction` property changes.
|
|
12
|
-
*/
|
|
13
|
-
export type GridSortColumnDirectionChangedEvent = CustomEvent<{ value: GridSorterDirection }>;
|
|
14
|
-
|
|
15
|
-
export interface GridSortColumnCustomEventMap {
|
|
16
|
-
'direction-changed': GridSortColumnDirectionChangedEvent;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface GridSortColumnEventMap extends HTMLElementEventMap, GridSortColumnCustomEventMap {}
|
|
10
|
+
export * from './vaadin-grid-sort-column-mixin.js';
|
|
20
11
|
|
|
21
12
|
/**
|
|
22
13
|
* `<vaadin-grid-sort-column>` is a helper element for the `<vaadin-grid>`
|
|
@@ -30,22 +21,13 @@ export interface GridSortColumnEventMap extends HTMLElementEventMap, GridSortCol
|
|
|
30
21
|
* <vaadin-grid-column>
|
|
31
22
|
* ...
|
|
32
23
|
* ```
|
|
33
|
-
*
|
|
34
|
-
* @fires {CustomEvent} direction-changed - Fired when the `direction` property changes.
|
|
35
24
|
*/
|
|
36
|
-
declare class GridSortColumn<TItem = GridDefaultItem> extends
|
|
37
|
-
/**
|
|
38
|
-
* JS Path of the property in the item used for sorting the data.
|
|
39
|
-
*/
|
|
40
|
-
path: string | null | undefined;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* How to sort the data.
|
|
44
|
-
* Possible values are `asc` to use an ascending algorithm, `desc` to sort the data in
|
|
45
|
-
* descending direction, or `null` for not sorting the data.
|
|
46
|
-
*/
|
|
47
|
-
direction: GridSorterDirection | null | undefined;
|
|
25
|
+
declare class GridSortColumn<TItem = GridDefaultItem> extends HTMLElement {}
|
|
48
26
|
|
|
27
|
+
interface GridSortColumn<TItem = GridDefaultItem>
|
|
28
|
+
extends GridSortColumnMixinClass,
|
|
29
|
+
GridColumnMixin<TItem, GridColumn<TItem>>,
|
|
30
|
+
GridColumn<TItem> {
|
|
49
31
|
addEventListener<K extends keyof GridSortColumnEventMap>(
|
|
50
32
|
type: K,
|
|
51
33
|
listener: (this: GridSortColumn<TItem>, ev: GridSortColumnEventMap[K]) => void,
|