forked from vaadin/vaadin-grid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vaadin-grid-active-item-mixin.html
56 lines (48 loc) · 1.34 KB
/
vaadin-grid-active-item-mixin.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!--
@license
Copyright (c) 2017 Vaadin Ltd.
This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
-->
<script>
window.Vaadin = window.Vaadin || {};
window.Vaadin.Grid = window.Vaadin.Grid || {};
/**
* @polymerMixin
*/
Vaadin.Grid.ActiveItemMixin = superClass => class ActiveItemMixin extends superClass {
static get properties() {
return {
/*
* The item user has last interacted with. Turns to `null` after user deactivates
* the item by re-interacting with the currently active item.
*/
activeItem: {
type: Object,
notify: true,
value: null
}
};
}
static get observers() {
return [
'_activeItemChanged(activeItem)'
];
}
ready() {
super.ready();
this.addEventListener('cell-activate', this._activateItem.bind(this));
}
_activateItem(e) {
const model = e.detail.model;
const clickedItem = model ? model.item : null;
if (clickedItem) {
this.activeItem = !this._itemsEqual(this.activeItem, clickedItem) ? clickedItem : null;
}
}
_activeItemChanged() {
if (this.$.scroller._physicalItems) {
this.$.scroller._physicalItems.forEach(row => this._updateItem(row, row.item));
}
}
};
</script>