-
Notifications
You must be signed in to change notification settings - Fork 155
/
vaadin-grid.html
103 lines (86 loc) · 2.99 KB
/
vaadin-grid.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="vaadin-grid-table.html">
<link rel="import" href="vaadin-grid-column.html">
<link rel="import" href="vaadin-grid-row-details-behavior.html">
<link rel="import" href="vaadin-grid-data-source-behavior.html">
<link rel="import" href="vaadin-grid-array-data-source-behavior.html">
<link rel="import" href="vaadin-grid-selection-behavior.html">
<link rel="import" href="vaadin-grid-sort-behavior.html">
<dom-module id="vaadin-grid">
<style>
:host {
display: block;
height: 400px;
/* default height to avoid accidental usage without explicit height */
--vaadin-grid-border-color: rgba(0, 0, 0, 0.08);
-webkit-tap-highlight-color: transparent;
}
#scroller {
height: 100%;
width: 100%;
}
</style>
<template>
<vaadin-grid-table loading$=[[loading]] bind-data="[[_bindData]]" size="[[size]]" id="scroller" columns="[[columns]]" frozen-columns=[[_frozenColumns]] content-target=[[_getContentTarget()]] row-details-template=[[rowDetailsTemplate]]>
<content></content>
</vaadin-grid-table>
</template>
</dom-module>
<script>
Polymer({
is: 'vaadin-grid',
properties: {
columns: {
type: Array,
notify: true
},
size: Number,
frozenColumns: {
type: Number,
value: 0
},
rowDetailsTemplate: Object,
_bindData: {
value: function() {
return this._getItem.bind(this);
}
}
},
behaviors: [
vaadin.elements.grid.RowDetailsBehavior,
vaadin.elements.grid.DataSourceBehavior,
vaadin.elements.grid.ArrayDataSourceBehavior,
vaadin.elements.grid.SelectionBehavior,
vaadin.elements.grid.SortBehavior
],
observers: ['_columnsChanged(columns.*)'],
_updateItem: function(row, item) {
row.style.minHeight = item ? '' : this.$.scroller._physicalAverage + 'px';
row.item = item;
row.selected = this._isSelected(item);
row.expanded = this._isExpanded(item);
},
_getContentTarget: function() {
return this;
},
_isFrozenColumn: function(column) {
return this.columns.indexOf(column) < this.frozenColumns;
},
ready: function() {
this.columns = Polymer.dom(this).querySelectorAll('vaadin-grid-column');
this.rowDetailsTemplate = Polymer.dom(this).querySelector('template[is=row-details]');
},
_columnsChanged: function(e) {
if (e.path === 'columns') { //new array is set
e.value.forEach(function(col) {
col.grid = this;
}.bind(this));
} else if (e.path === 'columns.splices' || //array is spliced
(e.path.indexOf('columns.#') === 0 && e.path.split('.').length === 2)) { //column is replaced with set
// TODO: implement splice support that will add and remove only affected cells.
// meanwhile, deal with splices as the whole array would change.
this.columns = this.columns.slice(0);
}
}
});
</script>