@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,139 @@
|
|
|
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
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @polymerMixin
|
|
9
|
+
*/
|
|
10
|
+
export const SortMixin = (superClass) =>
|
|
11
|
+
class SortMixin extends superClass {
|
|
12
|
+
static get properties() {
|
|
13
|
+
return {
|
|
14
|
+
/**
|
|
15
|
+
* When `true`, all `<vaadin-grid-sorter>` are applied for sorting.
|
|
16
|
+
* @attr {boolean} multi-sort
|
|
17
|
+
* @type {boolean}
|
|
18
|
+
*/
|
|
19
|
+
multiSort: {
|
|
20
|
+
type: Boolean,
|
|
21
|
+
value: false
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @type {!Array<!GridSorterDefinition>}
|
|
26
|
+
* @protected
|
|
27
|
+
*/
|
|
28
|
+
_sorters: {
|
|
29
|
+
type: Array,
|
|
30
|
+
value: function () {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
/** @private */
|
|
36
|
+
_previousSorters: {
|
|
37
|
+
type: Array,
|
|
38
|
+
value: function () {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** @protected */
|
|
46
|
+
ready() {
|
|
47
|
+
super.ready();
|
|
48
|
+
this.addEventListener('sorter-changed', this._onSorterChanged);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** @private */
|
|
52
|
+
_onSorterChanged(e) {
|
|
53
|
+
const sorter = e.target;
|
|
54
|
+
e.stopPropagation();
|
|
55
|
+
this.__updateSorter(sorter);
|
|
56
|
+
this.__applySorters();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @private */
|
|
60
|
+
__removeSorters(sortersToRemove) {
|
|
61
|
+
if (sortersToRemove.length == 0) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
this._sorters = this._sorters.filter((sorter) => sortersToRemove.indexOf(sorter) < 0);
|
|
66
|
+
if (this.multiSort) {
|
|
67
|
+
this.__updateSortOrders();
|
|
68
|
+
}
|
|
69
|
+
this.__applySorters();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** @private */
|
|
73
|
+
__updateSortOrders() {
|
|
74
|
+
this._sorters.forEach((sorter, index) => (sorter._order = this._sorters.length > 1 ? index : null), this);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** @private */
|
|
78
|
+
__updateSorter(sorter) {
|
|
79
|
+
if (!sorter.direction && this._sorters.indexOf(sorter) === -1) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
sorter._order = null;
|
|
84
|
+
|
|
85
|
+
if (this.multiSort) {
|
|
86
|
+
this._removeArrayItem(this._sorters, sorter);
|
|
87
|
+
if (sorter.direction) {
|
|
88
|
+
this._sorters.unshift(sorter);
|
|
89
|
+
}
|
|
90
|
+
this.__updateSortOrders();
|
|
91
|
+
} else {
|
|
92
|
+
if (sorter.direction) {
|
|
93
|
+
const otherSorters = this._sorters.filter((s) => s != sorter);
|
|
94
|
+
this._sorters = [sorter];
|
|
95
|
+
otherSorters.forEach((sorter) => {
|
|
96
|
+
sorter._order = null;
|
|
97
|
+
sorter.direction = null;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** @private */
|
|
104
|
+
__applySorters() {
|
|
105
|
+
if (
|
|
106
|
+
this.dataProvider &&
|
|
107
|
+
// No need to clear cache if sorters didn't change and grid is attached
|
|
108
|
+
this.isAttached &&
|
|
109
|
+
JSON.stringify(this._previousSorters) !== JSON.stringify(this._mapSorters())
|
|
110
|
+
) {
|
|
111
|
+
this.clearCache();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
this._a11yUpdateSorters();
|
|
115
|
+
|
|
116
|
+
this._previousSorters = this._mapSorters();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @return {!Array<!GridSorterDefinition>}
|
|
121
|
+
* @protected
|
|
122
|
+
*/
|
|
123
|
+
_mapSorters() {
|
|
124
|
+
return this._sorters.map((sorter) => {
|
|
125
|
+
return {
|
|
126
|
+
path: sorter.path,
|
|
127
|
+
direction: sorter.direction
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** @private */
|
|
133
|
+
_removeArrayItem(array, item) {
|
|
134
|
+
const index = array.indexOf(item);
|
|
135
|
+
if (index > -1) {
|
|
136
|
+
array.splice(index, 1);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
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 { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
7
|
+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
8
|
+
import { GridSorterDirection } from './interfaces';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Fired when the `direction` property changes.
|
|
12
|
+
*/
|
|
13
|
+
export type GridSorterDirectionChangedEvent = CustomEvent<{ value: GridSorterDirection }>;
|
|
14
|
+
|
|
15
|
+
export interface GridSorterCustomEventMap {
|
|
16
|
+
'sorter-changed': Event;
|
|
17
|
+
|
|
18
|
+
'direction-changed': GridSorterDirectionChangedEvent;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface GridSorterEventMap extends HTMLElementEventMap, GridSorterCustomEventMap {}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* `<vaadin-grid-sorter>` is a helper element for the `<vaadin-grid>` that provides out-of-the-box UI controls,
|
|
25
|
+
* visual feedback, and handlers for sorting the grid data.
|
|
26
|
+
*
|
|
27
|
+
* #### Example:
|
|
28
|
+
* ```html
|
|
29
|
+
* <vaadin-grid-column id="column"></vaadin-grid-column>
|
|
30
|
+
* ```
|
|
31
|
+
* ```js
|
|
32
|
+
* const column = document.querySelector('#column');
|
|
33
|
+
* column.renderer = (root, column, model) => {
|
|
34
|
+
* let sorter = root.firstElementChild;
|
|
35
|
+
* if (!sorter) {
|
|
36
|
+
* sorter = document.createElement('vaadin-grid-sorter');
|
|
37
|
+
* root.appendChild(sorter);
|
|
38
|
+
* }
|
|
39
|
+
* sorter.path = 'name.first';
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* ### Styling
|
|
44
|
+
*
|
|
45
|
+
* The following shadow DOM parts are available for styling:
|
|
46
|
+
*
|
|
47
|
+
* Part name | Description
|
|
48
|
+
* ----------------|----------------
|
|
49
|
+
* `content` | The slotted content wrapper
|
|
50
|
+
* `indicators` | The internal sorter indicators.
|
|
51
|
+
* `order` | The internal sorter order
|
|
52
|
+
*
|
|
53
|
+
* The following state attributes are available for styling:
|
|
54
|
+
*
|
|
55
|
+
* Attribute | Description | Part name
|
|
56
|
+
* -------------|-------------|------------
|
|
57
|
+
* `direction` | Sort direction of a sorter | :host
|
|
58
|
+
*
|
|
59
|
+
* @fires {CustomEvent} direction-changed - Fired when the `direction` property changes.
|
|
60
|
+
* @fires {CustomEvent} sorter-changed - Fired when the `path` or `direction` property changes.
|
|
61
|
+
*/
|
|
62
|
+
declare class GridSorter extends ThemableMixin(DirMixin(HTMLElement)) {
|
|
63
|
+
/**
|
|
64
|
+
* JS Path of the property in the item used for sorting the data.
|
|
65
|
+
*/
|
|
66
|
+
path: string | null | undefined;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* How to sort the data.
|
|
70
|
+
* Possible values are `asc` to use an ascending algorithm, `desc` to sort the data in
|
|
71
|
+
* descending direction, or `null` for not sorting the data.
|
|
72
|
+
*/
|
|
73
|
+
direction: GridSorterDirection | null | undefined;
|
|
74
|
+
|
|
75
|
+
addEventListener<K extends keyof GridSorterEventMap>(
|
|
76
|
+
type: K,
|
|
77
|
+
listener: (this: GridSorter, ev: GridSorterEventMap[K]) => void,
|
|
78
|
+
options?: boolean | AddEventListenerOptions
|
|
79
|
+
): void;
|
|
80
|
+
|
|
81
|
+
removeEventListener<K extends keyof GridSorterEventMap>(
|
|
82
|
+
type: K,
|
|
83
|
+
listener: (this: GridSorter, ev: GridSorterEventMap[K]) => void,
|
|
84
|
+
options?: boolean | EventListenerOptions
|
|
85
|
+
): void;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
declare global {
|
|
89
|
+
interface HTMLElementTagNameMap {
|
|
90
|
+
'vaadin-grid-sorter': GridSorter;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { GridSorter };
|
|
@@ -0,0 +1,230 @@
|
|
|
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
|
+
|
|
10
|
+
const $_documentContainer = document.createElement('template');
|
|
11
|
+
|
|
12
|
+
$_documentContainer.innerHTML = `
|
|
13
|
+
<style>
|
|
14
|
+
@font-face {
|
|
15
|
+
font-family: 'vaadin-grid-sorter-icons';
|
|
16
|
+
src: url(data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAAQwAA0AAAAABuwAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAAEFAAAABkAAAAcfep+mUdERUYAAAP4AAAAHAAAAB4AJwAOT1MvMgAAAZgAAAA/AAAAYA8TBPpjbWFwAAAB7AAAAFUAAAFeF1fZ4mdhc3AAAAPwAAAACAAAAAgAAAAQZ2x5ZgAAAlgAAABcAAAAnMvguMloZWFkAAABMAAAAC8AAAA2C5Ap72hoZWEAAAFgAAAAHQAAACQGbQPHaG10eAAAAdgAAAAUAAAAHAoAAABsb2NhAAACRAAAABIAAAASAIwAYG1heHAAAAGAAAAAFgAAACAACwAKbmFtZQAAArQAAAECAAACZxWCgKhwb3N0AAADuAAAADUAAABZCrApUXicY2BkYGAA4rDECVrx/DZfGbhZGEDgyqNPOxH0/wNMq5kPALkcDEwgUQBWRA0dAHicY2BkYGA+8P8AAwMLAwgwrWZgZEAFbABY4QM8AAAAeJxjYGRgYOAAQiYGEICQSAAAAi8AFgAAeJxjYGY6yziBgZWBgWkm0xkGBoZ+CM34msGYkZMBFTAKoAkwODAwvmRiPvD/AIMDMxCD1CDJKjAwAgBktQsXAHicY2GAAMZQCM0EwqshbAALxAEKeJxjYGBgZoBgGQZGBhCIAPIYwXwWBhsgzcXAwcAEhIwMCi+Z/v/9/x+sSuElA4T9/4k4K1gHFwMMMILMY2QDYmaoABOQYGJABUA7WBiGNwAAJd4NIQAAAAAAAAAACAAIABAAGAAmAEAATgAAeJyNjLENgDAMBP9tIURJwQCMQccSZgk2i5fIYBDAidJjycXr7x5EPwE2wY8si7jmyBNXGo/bNBerxJNrpxhbO3/fEFpx8ZICpV+ghxJ74fAMe+h7Ox14AbrsHB14nK2QQWrDMBRER4mTkhQK3ZRQKOgCNk7oGQqhhEIX2WSlWEI1BAlkJ5CDdNsj5Ey9Rncdi38ES+jzNJo/HwTgATcoDEthhY3wBHc4CE+pfwsX5F/hGe7Vo/AcK/UhvMSz+mGXKhZU6pww8ISz3oWn1BvhgnwTnuEJf8Jz1OpFeIlX9YULDLdFi4ASHolkSR0iuYdjLak1vAequBhj21D61Nqyi6l3qWybGPjySbPHGScGJl6dP58MYcQRI0bts7mjebBqrFENH7t3qWtj0OuqHnXcW7b0HOTZFnKryRGW2hFX1m0O2vEM3opNMfTau+CS6Z3Vx6veNnEXY6jwDxhsc2gAAHicY2BiwA84GBgYmRiYGJkZmBlZGFkZ2djScyoLMgzZS/MyDQwMwLSrpYEBlIbxjQDrzgsuAAAAAAEAAf//AA94nGNgZGBg4AFiMSBmYmAEQnYgZgHzGAAD6wA2eJxjYGBgZACCKyoz1cD0o087YTQATOcIewAAAA==) format('woff');
|
|
17
|
+
font-weight: normal;
|
|
18
|
+
font-style: normal;
|
|
19
|
+
}
|
|
20
|
+
</style>
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
document.head.appendChild($_documentContainer.content);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* `<vaadin-grid-sorter>` is a helper element for the `<vaadin-grid>` that provides out-of-the-box UI controls,
|
|
27
|
+
* visual feedback, and handlers for sorting the grid data.
|
|
28
|
+
*
|
|
29
|
+
* #### Example:
|
|
30
|
+
* ```html
|
|
31
|
+
* <vaadin-grid-column id="column"></vaadin-grid-column>
|
|
32
|
+
* ```
|
|
33
|
+
* ```js
|
|
34
|
+
* const column = document.querySelector('#column');
|
|
35
|
+
* column.renderer = (root, column, model) => {
|
|
36
|
+
* let sorter = root.firstElementChild;
|
|
37
|
+
* if (!sorter) {
|
|
38
|
+
* sorter = document.createElement('vaadin-grid-sorter');
|
|
39
|
+
* root.appendChild(sorter);
|
|
40
|
+
* }
|
|
41
|
+
* sorter.path = 'name.first';
|
|
42
|
+
* };
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* ### Styling
|
|
46
|
+
*
|
|
47
|
+
* The following shadow DOM parts are available for styling:
|
|
48
|
+
*
|
|
49
|
+
* Part name | Description
|
|
50
|
+
* ----------------|----------------
|
|
51
|
+
* `content` | The slotted content wrapper
|
|
52
|
+
* `indicators` | The internal sorter indicators.
|
|
53
|
+
* `order` | The internal sorter order
|
|
54
|
+
*
|
|
55
|
+
* The following state attributes are available for styling:
|
|
56
|
+
*
|
|
57
|
+
* Attribute | Description | Part name
|
|
58
|
+
* -------------|-------------|------------
|
|
59
|
+
* `direction` | Sort direction of a sorter | :host
|
|
60
|
+
*
|
|
61
|
+
* @fires {CustomEvent} direction-changed - Fired when the `direction` property changes.
|
|
62
|
+
* @fires {CustomEvent} sorter-changed - Fired when the `path` or `direction` property changes.
|
|
63
|
+
*
|
|
64
|
+
* @extends HTMLElement
|
|
65
|
+
*/
|
|
66
|
+
class GridSorter extends ThemableMixin(DirMixin(PolymerElement)) {
|
|
67
|
+
static get template() {
|
|
68
|
+
return html`
|
|
69
|
+
<style>
|
|
70
|
+
:host {
|
|
71
|
+
display: inline-flex;
|
|
72
|
+
cursor: pointer;
|
|
73
|
+
max-width: 100%;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
[part='content'] {
|
|
77
|
+
flex: 1 1 auto;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
[part='indicators'] {
|
|
81
|
+
position: relative;
|
|
82
|
+
align-self: center;
|
|
83
|
+
flex: none;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
[part='order'] {
|
|
87
|
+
display: inline;
|
|
88
|
+
vertical-align: super;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
[part='indicators']::before {
|
|
92
|
+
font-family: 'vaadin-grid-sorter-icons';
|
|
93
|
+
display: inline-block;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
:host(:not([direction])) [part='indicators']::before {
|
|
97
|
+
content: '\\e901';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
:host([direction='asc']) [part='indicators']::before {
|
|
101
|
+
content: '\\e900';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
:host([direction='desc']) [part='indicators']::before {
|
|
105
|
+
content: '\\e902';
|
|
106
|
+
}
|
|
107
|
+
</style>
|
|
108
|
+
|
|
109
|
+
<div part="content">
|
|
110
|
+
<slot></slot>
|
|
111
|
+
</div>
|
|
112
|
+
<div part="indicators">
|
|
113
|
+
<span part="order">[[_getDisplayOrder(_order)]]</span>
|
|
114
|
+
</div>
|
|
115
|
+
`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static get is() {
|
|
119
|
+
return 'vaadin-grid-sorter';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static get properties() {
|
|
123
|
+
return {
|
|
124
|
+
/**
|
|
125
|
+
* JS Path of the property in the item used for sorting the data.
|
|
126
|
+
*/
|
|
127
|
+
path: String,
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* How to sort the data.
|
|
131
|
+
* Possible values are `asc` to use an ascending algorithm, `desc` to sort the data in
|
|
132
|
+
* descending direction, or `null` for not sorting the data.
|
|
133
|
+
* @type {GridSorterDirection | undefined}
|
|
134
|
+
*/
|
|
135
|
+
direction: {
|
|
136
|
+
type: String,
|
|
137
|
+
reflectToAttribute: true,
|
|
138
|
+
notify: true,
|
|
139
|
+
value: null
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @type {number | null}
|
|
144
|
+
* @protected
|
|
145
|
+
*/
|
|
146
|
+
_order: {
|
|
147
|
+
type: Number,
|
|
148
|
+
value: null
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
/** @private */
|
|
152
|
+
_isConnected: {
|
|
153
|
+
type: Boolean,
|
|
154
|
+
observer: '__isConnectedChanged'
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static get observers() {
|
|
160
|
+
return ['_pathOrDirectionChanged(path, direction)'];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** @protected */
|
|
164
|
+
ready() {
|
|
165
|
+
super.ready();
|
|
166
|
+
this.addEventListener('click', this._onClick.bind(this));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** @protected */
|
|
170
|
+
connectedCallback() {
|
|
171
|
+
super.connectedCallback();
|
|
172
|
+
this._isConnected = true;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** @protected */
|
|
176
|
+
disconnectedCallback() {
|
|
177
|
+
super.disconnectedCallback();
|
|
178
|
+
this._isConnected = false;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** @private */
|
|
182
|
+
_pathOrDirectionChanged() {
|
|
183
|
+
this.__dispatchSorterChangedEvenIfPossible();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** @private */
|
|
187
|
+
__isConnectedChanged(newValue, oldValue) {
|
|
188
|
+
if (oldValue === false) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
this.__dispatchSorterChangedEvenIfPossible();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** @private */
|
|
196
|
+
__dispatchSorterChangedEvenIfPossible() {
|
|
197
|
+
if (this.path === undefined || this.direction === undefined || !this._isConnected) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
this.dispatchEvent(new CustomEvent('sorter-changed', { bubbles: true, composed: true }));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** @private */
|
|
205
|
+
_getDisplayOrder(order) {
|
|
206
|
+
return order === null ? '' : order + 1;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** @private */
|
|
210
|
+
_onClick(e) {
|
|
211
|
+
const activeElement = this.getRootNode().activeElement;
|
|
212
|
+
if (this !== activeElement && this.contains(activeElement)) {
|
|
213
|
+
// Some focusable content inside the sorter was clicked, do nothing.
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
e.preventDefault();
|
|
218
|
+
if (this.direction === 'asc') {
|
|
219
|
+
this.direction = 'desc';
|
|
220
|
+
} else if (this.direction === 'desc') {
|
|
221
|
+
this.direction = null;
|
|
222
|
+
} else {
|
|
223
|
+
this.direction = 'asc';
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
customElements.define(GridSorter.is, GridSorter);
|
|
229
|
+
|
|
230
|
+
export { GridSorter };
|