@vaadin/grid 22.0.0-alpha7
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/LICENSE +190 -0
- package/README.md +79 -0
- package/all-imports.js +1 -0
- package/package.json +58 -0
- package/src/all-imports.js +14 -0
- package/src/array-data-provider.js +145 -0
- package/src/interfaces.d.ts +75 -0
- package/src/vaadin-grid-a11y-mixin.js +158 -0
- package/src/vaadin-grid-active-item-mixin.d.ts +19 -0
- package/src/vaadin-grid-active-item-mixin.js +117 -0
- package/src/vaadin-grid-array-data-provider-mixin.d.ts +16 -0
- package/src/vaadin-grid-array-data-provider-mixin.js +75 -0
- package/src/vaadin-grid-column-group.d.ts +54 -0
- package/src/vaadin-grid-column-group.js +320 -0
- package/src/vaadin-grid-column-reordering-mixin.d.ts +19 -0
- package/src/vaadin-grid-column-reordering-mixin.js +387 -0
- package/src/vaadin-grid-column-resizing-mixin.js +111 -0
- package/src/vaadin-grid-column.d.ts +133 -0
- package/src/vaadin-grid-column.js +745 -0
- package/src/vaadin-grid-data-provider-mixin.d.ts +108 -0
- package/src/vaadin-grid-data-provider-mixin.js +520 -0
- package/src/vaadin-grid-drag-and-drop-mixin.d.ts +69 -0
- package/src/vaadin-grid-drag-and-drop-mixin.js +433 -0
- package/src/vaadin-grid-dynamic-columns-mixin.js +180 -0
- package/src/vaadin-grid-event-context-mixin.d.ts +33 -0
- package/src/vaadin-grid-event-context-mixin.js +57 -0
- package/src/vaadin-grid-filter-column.d.ts +35 -0
- package/src/vaadin-grid-filter-column.js +120 -0
- package/src/vaadin-grid-filter-mixin.js +76 -0
- package/src/vaadin-grid-filter.d.ts +67 -0
- package/src/vaadin-grid-filter.js +125 -0
- package/src/vaadin-grid-helpers.js +23 -0
- package/src/vaadin-grid-keyboard-navigation-mixin.js +891 -0
- package/src/vaadin-grid-row-details-mixin.d.ts +44 -0
- package/src/vaadin-grid-row-details-mixin.js +200 -0
- package/src/vaadin-grid-scroll-mixin.d.ts +18 -0
- package/src/vaadin-grid-scroll-mixin.js +202 -0
- package/src/vaadin-grid-selection-column.d.ts +71 -0
- package/src/vaadin-grid-selection-column.js +285 -0
- package/src/vaadin-grid-selection-mixin.d.ts +30 -0
- package/src/vaadin-grid-selection-mixin.js +93 -0
- package/src/vaadin-grid-sort-column.d.ts +63 -0
- package/src/vaadin-grid-sort-column.js +118 -0
- package/src/vaadin-grid-sort-mixin.d.ts +15 -0
- package/src/vaadin-grid-sort-mixin.js +139 -0
- package/src/vaadin-grid-sorter.d.ts +94 -0
- package/src/vaadin-grid-sorter.js +230 -0
- package/src/vaadin-grid-styles.js +297 -0
- package/src/vaadin-grid-styling-mixin.d.ts +37 -0
- package/src/vaadin-grid-styling-mixin.js +71 -0
- package/src/vaadin-grid-tree-column.d.ts +36 -0
- package/src/vaadin-grid-tree-column.js +119 -0
- package/src/vaadin-grid-tree-toggle.d.ts +104 -0
- package/src/vaadin-grid-tree-toggle.js +205 -0
- package/src/vaadin-grid.d.ts +397 -0
- package/src/vaadin-grid.js +1004 -0
- package/theme/lumo/all-imports.js +11 -0
- package/theme/lumo/vaadin-grid-column-group.js +1 -0
- package/theme/lumo/vaadin-grid-column.js +1 -0
- package/theme/lumo/vaadin-grid-filter-column.js +2 -0
- package/theme/lumo/vaadin-grid-filter.js +2 -0
- package/theme/lumo/vaadin-grid-selection-column.js +2 -0
- package/theme/lumo/vaadin-grid-sort-column.js +2 -0
- package/theme/lumo/vaadin-grid-sorter-styles.js +53 -0
- package/theme/lumo/vaadin-grid-sorter.js +2 -0
- package/theme/lumo/vaadin-grid-styles.js +378 -0
- package/theme/lumo/vaadin-grid-tree-column.js +2 -0
- package/theme/lumo/vaadin-grid-tree-toggle-styles.js +112 -0
- package/theme/lumo/vaadin-grid-tree-toggle.js +2 -0
- package/theme/lumo/vaadin-grid.js +9 -0
- package/theme/material/all-imports.js +11 -0
- package/theme/material/vaadin-grid-column-group.js +1 -0
- package/theme/material/vaadin-grid-column.js +1 -0
- package/theme/material/vaadin-grid-filter-column.js +2 -0
- package/theme/material/vaadin-grid-filter.js +2 -0
- package/theme/material/vaadin-grid-selection-column.js +2 -0
- package/theme/material/vaadin-grid-sort-column.js +2 -0
- package/theme/material/vaadin-grid-sorter-styles.js +72 -0
- package/theme/material/vaadin-grid-sorter.js +2 -0
- package/theme/material/vaadin-grid-styles.js +252 -0
- package/theme/material/vaadin-grid-tree-column.js +2 -0
- package/theme/material/vaadin-grid-tree-toggle-styles.js +42 -0
- package/theme/material/vaadin-grid-tree-toggle.js +2 -0
- package/theme/material/vaadin-grid.js +2 -0
- package/vaadin-grid-column-group.d.ts +1 -0
- package/vaadin-grid-column-group.js +3 -0
- package/vaadin-grid-column.d.ts +1 -0
- package/vaadin-grid-column.js +3 -0
- package/vaadin-grid-filter-column.d.ts +1 -0
- package/vaadin-grid-filter-column.js +3 -0
- package/vaadin-grid-filter.d.ts +1 -0
- package/vaadin-grid-filter.js +3 -0
- package/vaadin-grid-selection-column.d.ts +1 -0
- package/vaadin-grid-selection-column.js +3 -0
- package/vaadin-grid-sort-column.d.ts +1 -0
- package/vaadin-grid-sort-column.js +3 -0
- package/vaadin-grid-sorter.d.ts +1 -0
- package/vaadin-grid-sorter.js +3 -0
- package/vaadin-grid-tree-column.d.ts +1 -0
- package/vaadin-grid-tree-column.js +3 -0
- package/vaadin-grid-tree-toggle.d.ts +1 -0
- package/vaadin-grid-tree-toggle.js +3 -0
- package/vaadin-grid.d.ts +3 -0
- package/vaadin-grid.js +4 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
|
|
7
|
+
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
8
|
+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
9
|
+
import { isFocusable } from './vaadin-grid-active-item-mixin.js';
|
|
10
|
+
|
|
11
|
+
const $_documentContainer = document.createElement('template');
|
|
12
|
+
|
|
13
|
+
$_documentContainer.innerHTML = `
|
|
14
|
+
<style>
|
|
15
|
+
@font-face {
|
|
16
|
+
font-family: "vaadin-grid-tree-icons";
|
|
17
|
+
src: url(data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAAQkAA0AAAAABrwAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAAECAAAABoAAAAcgHwa6EdERUYAAAPsAAAAHAAAAB4AJwAOT1MvMgAAAZQAAAA/AAAAYA8TBIJjbWFwAAAB8AAAAFUAAAFeGJvXWmdhc3AAAAPkAAAACAAAAAgAAAAQZ2x5ZgAAAlwAAABLAAAAhIrPOhFoZWFkAAABMAAAACsAAAA2DsJI02hoZWEAAAFcAAAAHQAAACQHAgPHaG10eAAAAdQAAAAZAAAAHAxVAgBsb2NhAAACSAAAABIAAAASAIAAVG1heHAAAAF8AAAAGAAAACAACgAFbmFtZQAAAqgAAAECAAACTwflzbdwb3N0AAADrAAAADYAAABZQ7Ajh3icY2BkYGAA4twv3Vfi+W2+MnCzMIDANSOmbGSa2YEZRHEwMIEoAAoiB6sAeJxjYGRgYD7w/wADAwsDCDA7MDAyoAI2AFEEAtIAAAB4nGNgZGBg4GBgZgDRDAxMDGgAAAGbABB4nGNgZp7JOIGBlYGBaSbTGQYGhn4IzfiawZiRkwEVMAqgCTA4MDA+38d84P8BBgdmIAapQZJVYGAEAGc/C54AeJxjYYAAxlAIzQTELAwMBxgZGB0ACy0BYwAAAHicY2BgYGaAYBkGRgYQiADyGMF8FgYbIM3FwMHABISMDArP9/3/+/8/WJXC8z0Q9v8nEp5gHVwMMMAIMo+RDYiZoQJMQIKJARUA7WBhGN4AACFKDtoAAAAAAAAAAAgACAAQABgAJgA0AEIAAHichYvBEYBADAKBVHBjBT4swl9KS2k05o0XHd/yW1hAfBFwCv9sIlJu3nZaNS3PXAaXXHI8Lge7DlzF7C1RgXc7xkK6+gvcD2URmQB4nK2RQWoCMRiFX3RUqtCli65yADModOMBLLgQSqHddRFnQghIAnEUvEA3vUUP0LP0Fj1G+yb8R5iEhO9/ef/7FwFwj28o9EthiVp4hBlehcfUP4Ur8o/wBAv8CU+xVFvhOR7UB7tUdUdlVRJ6HnHWTnhM/V24In8JT5j/KzzFSi2E53hUz7jCcrcIiDDwyKSW1JEct2HdIPH1DFytbUM0PofWdNk5E5oUqb/Q6HHBiVGZpfOXkyUMEj5IyBuNmYZQjBobfsuassvnkKLe1OuBBj0VQ8cRni2xjLWsHaM0jrjx3peYA0/vrdmUYqe9iy7bzrX6eNP7Jh1SijX+AaUVbB8AAHicY2BiwA84GBgYmRiYGJkZmBlZGFkZ2djScyoLMgzZS/MyDQwMwLSruZMzlHaB0q4A76kLlwAAAAEAAf//AA94nGNgZGBg4AFiMSBmYmAEQnYgZgHzGAAD6wA2eJxjYGBgZACCKxJigiD6mhFTNowGACmcA/8AAA==) format('woff');
|
|
18
|
+
font-weight: normal;
|
|
19
|
+
font-style: normal;
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
document.head.appendChild($_documentContainer.content);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* `<vaadin-grid-tree-toggle>` is a helper element for the `<vaadin-grid>`
|
|
28
|
+
* that provides toggle and level display functionality for the item tree.
|
|
29
|
+
*
|
|
30
|
+
* #### Example:
|
|
31
|
+
* ```html
|
|
32
|
+
* <vaadin-grid-column id="column"></vaadin-grid-column>
|
|
33
|
+
* ```
|
|
34
|
+
* ```js
|
|
35
|
+
* const column = document.querySelector('#column');
|
|
36
|
+
* column.renderer = (root, column, model) => {
|
|
37
|
+
* let treeToggle = root.firstElementChild;
|
|
38
|
+
* if (!treeToggle) {
|
|
39
|
+
* treeToggle = document.createElement('vaadin-grid-tree-toggle');
|
|
40
|
+
* treeToggle.addEventListener('expanded-changed', () => { ... });
|
|
41
|
+
* root.appendChild(treeToggle);
|
|
42
|
+
* }
|
|
43
|
+
* treeToggle.leaf = !model.item.hasChildren;
|
|
44
|
+
* treeToggle.level = level;
|
|
45
|
+
* treeToggle.expanded = expanded;
|
|
46
|
+
* treeToggle.textContent = model.item.name;
|
|
47
|
+
* };
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* ### Styling
|
|
51
|
+
*
|
|
52
|
+
* The following shadow DOM parts are available for styling:
|
|
53
|
+
*
|
|
54
|
+
* Part name | Description
|
|
55
|
+
* ---|---
|
|
56
|
+
* `toggle` | The tree toggle icon
|
|
57
|
+
*
|
|
58
|
+
* The following state attributes are available for styling:
|
|
59
|
+
*
|
|
60
|
+
* Attribute | Description | Part name
|
|
61
|
+
* ---|---|---
|
|
62
|
+
* `expanded` | When present, the toggle is expanded | :host
|
|
63
|
+
* `leaf` | When present, the toggle is not expandable, i. e., the current item is a leaf | :host
|
|
64
|
+
*
|
|
65
|
+
* The following custom CSS properties are available on
|
|
66
|
+
* the `<vaadin-grid-tree-toggle>` element:
|
|
67
|
+
*
|
|
68
|
+
* Custom CSS property | Description | Default
|
|
69
|
+
* ---|---|---
|
|
70
|
+
* `--vaadin-grid-tree-toggle-level-offset` | Visual offset step for each tree sublevel | `1em`
|
|
71
|
+
*
|
|
72
|
+
* @fires {CustomEvent} expanded-changed - Fired when the `expanded` property changes.
|
|
73
|
+
*
|
|
74
|
+
* @extends HTMLElement
|
|
75
|
+
* @mixes ThemableMixin
|
|
76
|
+
*/
|
|
77
|
+
class GridTreeToggle extends ThemableMixin(DirMixin(PolymerElement)) {
|
|
78
|
+
static get template() {
|
|
79
|
+
return html`
|
|
80
|
+
<style>
|
|
81
|
+
:host {
|
|
82
|
+
display: inline-flex;
|
|
83
|
+
align-items: baseline;
|
|
84
|
+
|
|
85
|
+
/* CSS API for :host */
|
|
86
|
+
--vaadin-grid-tree-toggle-level-offset: 1em;
|
|
87
|
+
--_collapsed-icon: '\\e7be\\00a0';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
:host([dir='rtl']) {
|
|
91
|
+
--_collapsed-icon: '\\e7bd\\00a0';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
:host([hidden]) {
|
|
95
|
+
display: none !important;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
:host(:not([leaf])) {
|
|
99
|
+
cursor: pointer;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
#level-spacer,
|
|
103
|
+
[part='toggle'] {
|
|
104
|
+
flex: none;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
#level-spacer {
|
|
108
|
+
display: inline-block;
|
|
109
|
+
width: calc(var(---level, '0') * var(--vaadin-grid-tree-toggle-level-offset));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
[part='toggle']::before {
|
|
113
|
+
font-family: 'vaadin-grid-tree-icons';
|
|
114
|
+
line-height: 1em; /* make icon font metrics not affect baseline */
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
:host(:not([expanded])) [part='toggle']::before {
|
|
118
|
+
content: var(--_collapsed-icon);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
:host([expanded]) [part='toggle']::before {
|
|
122
|
+
content: '\\e7bc\\00a0'; /* icon glyph + single non-breaking space */
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
:host([leaf]) [part='toggle'] {
|
|
126
|
+
visibility: hidden;
|
|
127
|
+
}
|
|
128
|
+
</style>
|
|
129
|
+
|
|
130
|
+
<span id="level-spacer"></span>
|
|
131
|
+
<span part="toggle"></span>
|
|
132
|
+
<slot></slot>
|
|
133
|
+
`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
static get is() {
|
|
137
|
+
return 'vaadin-grid-tree-toggle';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
static get properties() {
|
|
141
|
+
return {
|
|
142
|
+
/**
|
|
143
|
+
* Current level of the tree represented with a horizontal offset
|
|
144
|
+
* of the toggle button.
|
|
145
|
+
* @type {number}
|
|
146
|
+
*/
|
|
147
|
+
level: {
|
|
148
|
+
type: Number,
|
|
149
|
+
value: 0,
|
|
150
|
+
observer: '_levelChanged'
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Hides the toggle icon and disables toggling a tree sublevel.
|
|
155
|
+
* @type {boolean}
|
|
156
|
+
*/
|
|
157
|
+
leaf: {
|
|
158
|
+
type: Boolean,
|
|
159
|
+
value: false,
|
|
160
|
+
reflectToAttribute: true
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Sublevel toggle state.
|
|
165
|
+
* @type {boolean}
|
|
166
|
+
*/
|
|
167
|
+
expanded: {
|
|
168
|
+
type: Boolean,
|
|
169
|
+
value: false,
|
|
170
|
+
reflectToAttribute: true,
|
|
171
|
+
notify: true
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** @protected */
|
|
177
|
+
ready() {
|
|
178
|
+
super.ready();
|
|
179
|
+
|
|
180
|
+
this.addEventListener('click', (e) => this._onClick(e));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** @private */
|
|
184
|
+
_onClick(e) {
|
|
185
|
+
if (this.leaf) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (isFocusable(e.target)) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
e.preventDefault();
|
|
193
|
+
this.expanded = !this.expanded;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** @private */
|
|
197
|
+
_levelChanged(level) {
|
|
198
|
+
const value = Number(level).toString();
|
|
199
|
+
this.style.setProperty('---level', value);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
customElements.define(GridTreeToggle.is, GridTreeToggle);
|
|
204
|
+
|
|
205
|
+
export { GridTreeToggle };
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
2
|
+
|
|
3
|
+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
4
|
+
|
|
5
|
+
import { GridDefaultItem, GridDropLocation, GridEventContext, GridItemModel } from './interfaces';
|
|
6
|
+
|
|
7
|
+
import { ActiveItemMixin } from './vaadin-grid-active-item-mixin.js';
|
|
8
|
+
|
|
9
|
+
import { ArrayDataProviderMixin } from './vaadin-grid-array-data-provider-mixin.js';
|
|
10
|
+
|
|
11
|
+
import { DataProviderMixin } from './vaadin-grid-data-provider-mixin.js';
|
|
12
|
+
|
|
13
|
+
import { EventContextMixin } from './vaadin-grid-event-context-mixin.js';
|
|
14
|
+
|
|
15
|
+
import { RowDetailsMixin } from './vaadin-grid-row-details-mixin.js';
|
|
16
|
+
|
|
17
|
+
import { ScrollMixin } from './vaadin-grid-scroll-mixin.js';
|
|
18
|
+
|
|
19
|
+
import { SelectionMixin } from './vaadin-grid-selection-mixin.js';
|
|
20
|
+
|
|
21
|
+
import { SortMixin } from './vaadin-grid-sort-mixin.js';
|
|
22
|
+
|
|
23
|
+
import { StylingMixin } from './vaadin-grid-styling-mixin.js';
|
|
24
|
+
|
|
25
|
+
import { DragAndDropMixin } from './vaadin-grid-drag-and-drop-mixin.js';
|
|
26
|
+
|
|
27
|
+
import { ColumnReorderingMixin } from './vaadin-grid-column-reordering-mixin.js';
|
|
28
|
+
|
|
29
|
+
import { GridColumn } from './vaadin-grid-column.js';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Fired when the `activeItem` property changes.
|
|
33
|
+
*/
|
|
34
|
+
export type GridActiveItemChangedEvent<TItem> = CustomEvent<{ value: TItem }>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Fired when the cell is activated with click or keyboard.
|
|
38
|
+
*/
|
|
39
|
+
export type GridCellActivateEvent<TItem> = CustomEvent<{ model: GridItemModel<TItem> }>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Fired when a cell is focused with click or keyboard navigation.
|
|
43
|
+
*/
|
|
44
|
+
export type GridCellFocusEvent<TItem> = CustomEvent<{ context: GridEventContext<TItem> }>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Fired when the columns in the grid are reordered.
|
|
48
|
+
*/
|
|
49
|
+
export type GridColumnReorderEvent<TItem> = CustomEvent<{ columns: GridColumn<TItem>[] }>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Fired when the grid column resize is finished.
|
|
53
|
+
*/
|
|
54
|
+
export type GridColumnResizeEvent<TItem> = CustomEvent<{ resizedColumn: GridColumn<TItem> }>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Fired when the `expandedItems` property changes.
|
|
58
|
+
*/
|
|
59
|
+
export type GridExpandedItemsChangedEvent<TItem> = CustomEvent<{ value: TItem[] }>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Fired when starting to drag grid rows.
|
|
63
|
+
*/
|
|
64
|
+
export type GridDragStartEvent<TItem> = CustomEvent<{
|
|
65
|
+
draggedItems: TItem[];
|
|
66
|
+
setDraggedItemsCount: (count: number) => void;
|
|
67
|
+
setDragData: (type: string, data: string) => void;
|
|
68
|
+
}>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Fired when a drop occurs on top of the grid.
|
|
72
|
+
*/
|
|
73
|
+
export type GridDropEvent<TItem> = CustomEvent<{
|
|
74
|
+
dropTargetItem: TItem;
|
|
75
|
+
dropLocation: GridDropLocation;
|
|
76
|
+
dragData: Array<{ type: string; data: string }>;
|
|
77
|
+
}>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Fired when the `loading` property changes.
|
|
81
|
+
*/
|
|
82
|
+
export type GridLoadingChangedEvent = CustomEvent<{ value: boolean }>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Fired when the `selectedItems` property changes.
|
|
86
|
+
*/
|
|
87
|
+
export type GridSelectedItemsChangedEvent<TItem> = CustomEvent<{ value: TItem[] }>;
|
|
88
|
+
|
|
89
|
+
export interface GridCustomEventMap<TItem> {
|
|
90
|
+
'active-item-changed': GridActiveItemChangedEvent<TItem>;
|
|
91
|
+
|
|
92
|
+
'cell-activate': GridCellActivateEvent<TItem>;
|
|
93
|
+
|
|
94
|
+
'cell-focus': GridCellFocusEvent<TItem>;
|
|
95
|
+
|
|
96
|
+
'column-reorder': GridColumnReorderEvent<TItem>;
|
|
97
|
+
|
|
98
|
+
'column-resize': GridColumnResizeEvent<TItem>;
|
|
99
|
+
|
|
100
|
+
'expanded-items-changed': GridExpandedItemsChangedEvent<TItem>;
|
|
101
|
+
|
|
102
|
+
'grid-dragstart': GridDragStartEvent<TItem>;
|
|
103
|
+
|
|
104
|
+
'grid-dragend': Event;
|
|
105
|
+
|
|
106
|
+
'grid-drop': GridDropEvent<TItem>;
|
|
107
|
+
|
|
108
|
+
'loading-changed': GridLoadingChangedEvent;
|
|
109
|
+
|
|
110
|
+
'selected-items-changed': GridSelectedItemsChangedEvent<TItem>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface GridEventMap<TItem> extends HTMLElementEventMap, GridCustomEventMap<TItem> {}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* `<vaadin-grid>` is a free, high quality data grid / data table Web Component. The content of the
|
|
117
|
+
* the grid can be populated by using renderer callback function.
|
|
118
|
+
*
|
|
119
|
+
* ### Quick Start
|
|
120
|
+
*
|
|
121
|
+
* Start with an assigning an array to the [`items`](#/elements/vaadin-grid#property-items) property to visualize your data.
|
|
122
|
+
*
|
|
123
|
+
* Use the [`<vaadin-grid-column>`](#/elements/vaadin-grid-column) element to configure the grid columns. Set `path` and `header`
|
|
124
|
+
* shorthand properties for the columns to define what gets rendered in the cells of the column.
|
|
125
|
+
*
|
|
126
|
+
* #### Example:
|
|
127
|
+
* ```html
|
|
128
|
+
* <vaadin-grid>
|
|
129
|
+
* <vaadin-grid-column path="name.first" header="First name"></vaadin-grid-column>
|
|
130
|
+
* <vaadin-grid-column path="name.last" header="Last name"></vaadin-grid-column>
|
|
131
|
+
* <vaadin-grid-column path="email"></vaadin-grid-column>
|
|
132
|
+
* </vaadin-grid>
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* For custom content `vaadin-grid-column` element provides you with three types of `renderer` callback functions: `headerRenderer`,
|
|
136
|
+
* `renderer` and `footerRenderer`.
|
|
137
|
+
*
|
|
138
|
+
* Each of those renderer functions provides `root`, `column`, `model` arguments when applicable.
|
|
139
|
+
* Generate DOM content, append it to the `root` element and control the state
|
|
140
|
+
* of the host element by accessing `column`. Before generating new content,
|
|
141
|
+
* users are able to check if there is already content in `root` for reusing it.
|
|
142
|
+
*
|
|
143
|
+
* Renderers are called on initialization of new column cells and each time the
|
|
144
|
+
* related row model is updated. DOM generated during the renderer call can be reused
|
|
145
|
+
* in the next renderer call and will be provided with the `root` argument.
|
|
146
|
+
* On first call it will be empty.
|
|
147
|
+
*
|
|
148
|
+
* #### Example:
|
|
149
|
+
* ```html
|
|
150
|
+
* <vaadin-grid>
|
|
151
|
+
* <vaadin-grid-column></vaadin-grid-column>
|
|
152
|
+
* <vaadin-grid-column></vaadin-grid-column>
|
|
153
|
+
* <vaadin-grid-column></vaadin-grid-column>
|
|
154
|
+
* </vaadin-grid>
|
|
155
|
+
* ```
|
|
156
|
+
* ```js
|
|
157
|
+
* const grid = document.querySelector('vaadin-grid');
|
|
158
|
+
* grid.items = [{'name': 'John', 'surname': 'Lennon', 'role': 'singer'},
|
|
159
|
+
* {'name': 'Ringo', 'surname': 'Starr', 'role': 'drums'}];
|
|
160
|
+
*
|
|
161
|
+
* const columns = grid.querySelectorAll('vaadin-grid-column');
|
|
162
|
+
*
|
|
163
|
+
* columns[0].headerRenderer = function(root) {
|
|
164
|
+
* root.textContent = 'Name';
|
|
165
|
+
* };
|
|
166
|
+
* columns[0].renderer = function(root, column, model) {
|
|
167
|
+
* root.textContent = model.item.name;
|
|
168
|
+
* };
|
|
169
|
+
*
|
|
170
|
+
* columns[1].headerRenderer = function(root) {
|
|
171
|
+
* root.textContent = 'Surname';
|
|
172
|
+
* };
|
|
173
|
+
* columns[1].renderer = function(root, column, model) {
|
|
174
|
+
* root.textContent = model.item.surname;
|
|
175
|
+
* };
|
|
176
|
+
*
|
|
177
|
+
* columns[2].headerRenderer = function(root) {
|
|
178
|
+
* root.textContent = 'Role';
|
|
179
|
+
* };
|
|
180
|
+
* columns[2].renderer = function(root, column, model) {
|
|
181
|
+
* root.textContent = model.item.role;
|
|
182
|
+
* };
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* The following properties are available in the `model` argument:
|
|
186
|
+
*
|
|
187
|
+
* Property name | Type | Description
|
|
188
|
+
* --------------|------|------------
|
|
189
|
+
* `index`| Number | The index of the item.
|
|
190
|
+
* `item` | String or Object | The item.
|
|
191
|
+
* `level` | Number | Number of the item's tree sublevel, starts from 0.
|
|
192
|
+
* `expanded` | Boolean | True if the item's tree sublevel is expanded.
|
|
193
|
+
* `selected` | Boolean | True if the item is selected.
|
|
194
|
+
* `detailsOpened` | Boolean | True if the item's row details are open.
|
|
195
|
+
*
|
|
196
|
+
* The following helper elements can be used for further customization:
|
|
197
|
+
* - [`<vaadin-grid-column-group>`](#/elements/vaadin-grid-column-group)
|
|
198
|
+
* - [`<vaadin-grid-filter>`](#/elements/vaadin-grid-filter)
|
|
199
|
+
* - [`<vaadin-grid-sorter>`](#/elements/vaadin-grid-sorter)
|
|
200
|
+
* - [`<vaadin-grid-selection-column>`](#/elements/vaadin-grid-selection-column)
|
|
201
|
+
* - [`<vaadin-grid-tree-toggle>`](#/elements/vaadin-grid-tree-toggle)
|
|
202
|
+
*
|
|
203
|
+
* __Note that the helper elements must be explicitly imported.__
|
|
204
|
+
* If you want to import everything at once you can use the `all-imports.html` bundle.
|
|
205
|
+
*
|
|
206
|
+
* ### Lazy Loading with Function Data Provider
|
|
207
|
+
*
|
|
208
|
+
* In addition to assigning an array to the items property, you can alternatively
|
|
209
|
+
* provide the `<vaadin-grid>` data through the
|
|
210
|
+
* [`dataProvider`](#/elements/vaadin-grid#property-dataProvider) function property.
|
|
211
|
+
* The `<vaadin-grid>` calls this function lazily, only when it needs more data
|
|
212
|
+
* to be displayed.
|
|
213
|
+
*
|
|
214
|
+
* See the [`dataProvider`](#/elements/vaadin-grid#property-dataProvider) in
|
|
215
|
+
* the API reference below for the detailed data provider arguments description,
|
|
216
|
+
* and the “Assigning Data” page in the demos.
|
|
217
|
+
*
|
|
218
|
+
* __Note that expanding the tree grid's item will trigger a call to the `dataProvider`.__
|
|
219
|
+
*
|
|
220
|
+
* __Also, note that when using function data providers, the total number of items
|
|
221
|
+
* needs to be set manually. The total number of items can be returned
|
|
222
|
+
* in the second argument of the data provider callback:__
|
|
223
|
+
*
|
|
224
|
+
* ```javascript
|
|
225
|
+
* grid.dataProvider = function(params, callback) {
|
|
226
|
+
* const url = 'https://api.example/data' +
|
|
227
|
+
* '?page=' + params.page + // the requested page index
|
|
228
|
+
* '&per_page=' + params.pageSize; // number of items on the page
|
|
229
|
+
* const xhr = new XMLHttpRequest();
|
|
230
|
+
* xhr.onload = function() {
|
|
231
|
+
* const response = JSON.parse(xhr.responseText);
|
|
232
|
+
* callback(
|
|
233
|
+
* response.employees, // requested page of items
|
|
234
|
+
* response.totalSize // total number of items
|
|
235
|
+
* );
|
|
236
|
+
* };
|
|
237
|
+
* xhr.open('GET', url, true);
|
|
238
|
+
* xhr.send();
|
|
239
|
+
* };
|
|
240
|
+
* ```
|
|
241
|
+
*
|
|
242
|
+
* __Alternatively, you can use the `size` property to set the total number of items:__
|
|
243
|
+
*
|
|
244
|
+
* ```javascript
|
|
245
|
+
* grid.size = 200; // The total number of items
|
|
246
|
+
* grid.dataProvider = function(params, callback) {
|
|
247
|
+
* const url = 'https://api.example/data' +
|
|
248
|
+
* '?page=' + params.page + // the requested page index
|
|
249
|
+
* '&per_page=' + params.pageSize; // number of items on the page
|
|
250
|
+
* const xhr = new XMLHttpRequest();
|
|
251
|
+
* xhr.onload = function() {
|
|
252
|
+
* const response = JSON.parse(xhr.responseText);
|
|
253
|
+
* callback(response.employees);
|
|
254
|
+
* };
|
|
255
|
+
* xhr.open('GET', url, true);
|
|
256
|
+
* xhr.send();
|
|
257
|
+
* };
|
|
258
|
+
* ```
|
|
259
|
+
*
|
|
260
|
+
* ### Styling
|
|
261
|
+
*
|
|
262
|
+
* The following shadow DOM parts are available for styling:
|
|
263
|
+
*
|
|
264
|
+
* Part name | Description
|
|
265
|
+
* ----------------|----------------
|
|
266
|
+
* `row` | Row in the internal table
|
|
267
|
+
* `cell` | Cell in the internal table
|
|
268
|
+
* `header-cell` | Header cell in the internal table
|
|
269
|
+
* `body-cell` | Body cell in the internal table
|
|
270
|
+
* `footer-cell` | Footer cell in the internal table
|
|
271
|
+
* `details-cell` | Row details cell in the internal table
|
|
272
|
+
* `resize-handle` | Handle for resizing the columns
|
|
273
|
+
* `reorder-ghost` | Ghost element of the header cell being dragged
|
|
274
|
+
*
|
|
275
|
+
* The following state attributes are available for styling:
|
|
276
|
+
*
|
|
277
|
+
* Attribute | Description | Part name
|
|
278
|
+
* -------------|-------------|------------
|
|
279
|
+
* `loading` | Set when the grid is loading data from data provider | :host
|
|
280
|
+
* `interacting` | Keyboard navigation in interaction mode | :host
|
|
281
|
+
* `navigating` | Keyboard navigation in navigation mode | :host
|
|
282
|
+
* `overflow` | Set when rows are overflowing the grid viewport. Possible values: `top`, `bottom`, `left`, `right` | :host
|
|
283
|
+
* `reordering` | Set when the grid's columns are being reordered | :host
|
|
284
|
+
* `dragover` | Set when the grid (not a specific row) is dragged over | :host
|
|
285
|
+
* `dragging-rows` : Set when grid rows are dragged | :host
|
|
286
|
+
* `reorder-status` | Reflects the status of a cell while columns are being reordered | cell
|
|
287
|
+
* `frozen` | Frozen cell | cell
|
|
288
|
+
* `last-frozen` | Last frozen cell | cell
|
|
289
|
+
* * `first-column` | First visible cell on a row | cell
|
|
290
|
+
* `last-column` | Last visible cell on a row | cell
|
|
291
|
+
* `selected` | Selected row | row
|
|
292
|
+
* `expanded` | Expanded row | row
|
|
293
|
+
* `details-opened` | Row with details open | row
|
|
294
|
+
* `loading` | Row that is waiting for data from data provider | row
|
|
295
|
+
* `odd` | Odd row | row
|
|
296
|
+
* `first` | The first body row | row
|
|
297
|
+
* `dragstart` | Set for one frame when drag of a row is starting. The value is a number when multiple rows are dragged | row
|
|
298
|
+
* `dragover` | Set when the row is dragged over | row
|
|
299
|
+
* `drag-disabled` | Set to a row that isn't available for dragging | row
|
|
300
|
+
* `drop-disabled` | Set to a row that can't be dropped on top of | row
|
|
301
|
+
*
|
|
302
|
+
* See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
|
|
303
|
+
*
|
|
304
|
+
* @fires {CustomEvent} active-item-changed - Fired when the `activeItem` property changes.
|
|
305
|
+
* @fires {CustomEvent} cell-activate - Fired when the cell is activated with click or keyboard.
|
|
306
|
+
* @fires {CustomEvent} cell-focus - Fired when a cell is focused with click or keyboard navigation.
|
|
307
|
+
* @fires {CustomEvent} column-reorder - Fired when the columns in the grid are reordered.
|
|
308
|
+
* @fires {CustomEvent} column-resize - Fired when the grid column resize is finished.
|
|
309
|
+
* @fires {CustomEvent} expanded-items-changed - Fired when the `expandedItems` property changes.
|
|
310
|
+
* @fires {CustomEvent} grid-dragstart - Fired when starting to drag grid rows.
|
|
311
|
+
* @fires {CustomEvent} grid-dragend - Fired when the dragging of the rows ends.
|
|
312
|
+
* @fires {CustomEvent} grid-drop - Fired when a drop occurs on top of the grid.
|
|
313
|
+
* @fires {CustomEvent} loading-changed - Fired when the `loading` property changes.
|
|
314
|
+
* @fires {CustomEvent} selected-items-changed - Fired when the `selectedItems` property changes.
|
|
315
|
+
*/
|
|
316
|
+
declare class Grid<TItem = GridDefaultItem> extends HTMLElement {
|
|
317
|
+
/**
|
|
318
|
+
* If true, the grid's height is defined by its rows.
|
|
319
|
+
*
|
|
320
|
+
* Effectively, this disables the grid's virtual scrolling so that all the rows are rendered in the DOM at once.
|
|
321
|
+
* If the grid has a large number of items, using the feature is discouraged to avoid performance issues.
|
|
322
|
+
* @attr {boolean} all-rows-visible
|
|
323
|
+
*/
|
|
324
|
+
allRowsVisible: boolean;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Updates the `width` of all columns which have `autoWidth` set to `true`.
|
|
328
|
+
*/
|
|
329
|
+
recalculateColumnWidths(): void;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Requests an update for the content of cells.
|
|
333
|
+
*
|
|
334
|
+
* While performing the update, the following renderers are invoked:
|
|
335
|
+
* - `Grid.rowDetailsRenderer`
|
|
336
|
+
* - `GridColumn.renderer`
|
|
337
|
+
* - `GridColumn.headerRenderer`
|
|
338
|
+
* - `GridColumn.footerRenderer`
|
|
339
|
+
*
|
|
340
|
+
* It is not guaranteed that the update happens immediately (synchronously) after it is requested.
|
|
341
|
+
*/
|
|
342
|
+
requestContentUpdate(): void;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Manually invoke existing renderers for all the columns
|
|
346
|
+
* (header, footer and body cells) and opened row details.
|
|
347
|
+
*
|
|
348
|
+
* @deprecated Since Vaadin 21, `render()` is deprecated. Please use `requestContentUpdate()` instead.
|
|
349
|
+
*/
|
|
350
|
+
render(): void;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Updates the computed metrics and positioning of internal grid parts
|
|
354
|
+
* (row/details cell positioning etc). Needs to be invoked whenever the sizing of grid
|
|
355
|
+
* content changes asynchronously to ensure consistent appearance (e.g. when a
|
|
356
|
+
* contained image whose bounds aren't known beforehand finishes loading).
|
|
357
|
+
*
|
|
358
|
+
* @deprecated Since Vaadin 22, `notifyResize()` is deprecated. The component uses a
|
|
359
|
+
* ResizeObserver internally and doesn't need to be explicitly notified of resizes.
|
|
360
|
+
*/
|
|
361
|
+
notifyResize(): void;
|
|
362
|
+
|
|
363
|
+
addEventListener<K extends keyof GridEventMap<TItem>>(
|
|
364
|
+
type: K,
|
|
365
|
+
listener: (this: Grid<TItem>, ev: GridEventMap<TItem>[K]) => void,
|
|
366
|
+
options?: boolean | AddEventListenerOptions
|
|
367
|
+
): void;
|
|
368
|
+
|
|
369
|
+
removeEventListener<K extends keyof GridEventMap<TItem>>(
|
|
370
|
+
type: K,
|
|
371
|
+
listener: (this: Grid<TItem>, ev: GridEventMap<TItem>[K]) => void,
|
|
372
|
+
options?: boolean | EventListenerOptions
|
|
373
|
+
): void;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
interface Grid<TItem = GridDefaultItem>
|
|
377
|
+
extends ElementMixin,
|
|
378
|
+
ThemableMixin,
|
|
379
|
+
ActiveItemMixin<TItem>,
|
|
380
|
+
ArrayDataProviderMixin<TItem>,
|
|
381
|
+
DataProviderMixin<TItem>,
|
|
382
|
+
RowDetailsMixin<TItem>,
|
|
383
|
+
ScrollMixin,
|
|
384
|
+
SelectionMixin<TItem>,
|
|
385
|
+
SortMixin,
|
|
386
|
+
ColumnReorderingMixin,
|
|
387
|
+
EventContextMixin<TItem>,
|
|
388
|
+
StylingMixin<TItem>,
|
|
389
|
+
DragAndDropMixin<TItem> {}
|
|
390
|
+
|
|
391
|
+
declare global {
|
|
392
|
+
interface HTMLElementTagNameMap {
|
|
393
|
+
'vaadin-grid': Grid<GridDefaultItem>;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export { Grid };
|