forked from EdgeVerve/oe-data-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oe-data-table-filter.html
253 lines (206 loc) · 6.93 KB
/
oe-data-table-filter.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<!--
©2016-2017 EdgeVerve Systems Limited (a fully owned Infosys subsidiary),
Bangalore, India. All Rights Reserved.
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-list/iron-list.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../paper-item/paper-item.html">
<link rel="import" href="../paper-checkbox/paper-checkbox.html">
<link rel="import" href="../paper-button/paper-button.html">
<!--
### oe-data-table-filter
`<oe-data-table-filter>` is used in `oe-data-table` component for displayig a column filter data. List of unique items present in a column is shown.
-->
<dom-module id="oe-data-table-filter">
<template>
<style>
:host {
display: block;
margin: 0 !important;
padding: 0 !important;
}
#list {
height: 192px;
width: 100%;
min-width: 100px;
}
.input-container {
padding: 16px;
border-bottom: 1px solid #ededed;
@apply(--layout);
@apply(--layout-center);
}
paper-input {
width: 100%;
--paper-input-container: {
padding: 0;
}
--paper-input-container-input: {
font-size: 13px;
}
}
paper-checkbox {
--paper-checkbox-size: 14px;
--paper-checkbox-ink-size: 38px;
}
paper-item {
--paper-item: {
font-size: 13px;
}
}
paper-button {
--paper-button: {
color: #2196f3;
font-size: 14px;
letter-spacing: 0.5px;
}
}
.action-buttons {
padding: 8px 5px;
font-weight: bold;
@apply(--layout);
@apply(--layout-around-justified);
}
</style>
<div class="input-container">
<paper-checkbox checked={{_selectAllItems}} on-change="_toggleSelectAll"> </paper-checkbox>
<paper-input label="Search [[column.label]]" no-label-float value={{searchText}} on-input="_computeCheckBox"></paper-input>
</div>
<template is="dom-if" if=[[!searchText.length]] on-dom-change="_updateListSize">
<iron-list id="list" items=[[_filterItems(_items,searchText)]]>
<template>
<paper-item tabindex="-1">
<paper-checkbox checked={{_getSelectionState(item,_computeSelection)}} on-change="_toggleCheckboxSelection"> [[item]] </paper-checkbox>
</paper-item>
</template>
</iron-list>
</template>
<template is="dom-if" if=[[searchText.length]] on-dom-change="_updateListSize">
<iron-list id="list" items=[[_filterItems(_items,searchText)]]>
<template>
<paper-item>
<paper-checkbox checked={{_getSelectionState(item,_computeSelection)}} on-change="_toggleCheckboxSelection"> [[item]] </paper-checkbox>
</paper-item>
</template>
</iron-list>
</template>
<div class="action-buttons">
<paper-button on-tap="_resetFilter"> Reset </paper-button>
<paper-button on-tap="_closeFilter"> Cancel </paper-button>
<paper-button on-tap="_applyFilter"> Apply </paper-button>
</div>
</template>
</dom-module>
<script>
Polymer({
is: 'oe-data-table-filter',
properties: {
/**
* The definition of the column of the current cell.
*
* @type {{key: string, label: string, uiType: string, type: string, sort: string}}
*/
column: {
type: Object,
notify: true
},
/**
* data object array.
*/
items: {
type: Array
}
},
get _selectedItems() {
return this._items.filter(function (item) {
return this._selectionState[item];
}.bind(this));
},
observers: [
'_itemsChanged(items.*)'
],
ready: function () {
this.set('_selectionState', {});
},
_computeCellData: function (row, column) {
var key = column.key || column.field;
return key ? row[key] : null;
},
_applyFilter: function (evt) { // eslint-disable-line no-unused-vars
this.set('column.selectedItems', this._selectedItems);
this.fire('apply-criteria');
this.domHost.$.dialog.close();
},
_resetFilter: function (evt) { // eslint-disable-line no-unused-vars
this._selectedItems.forEach(function (item) {
this.set('_selectionState.' + item, false);
}.bind(this));
this.set('_selectAllItems', false);
this.set('_computeSelection', !this._computeSelection);
this.set('column.selectedItems', this._selectedItems);
this.fire('apply-criteria');
this.domHost.$.dialog.close();
},
_closeFilter: function (event) { // eslint-disable-line no-unused-vars
this.domHost.$.dialog.close();
},
_itemsChanged: function (change) { // eslint-disable-line no-unused-vars
//console.log(change);
// if (change.path == 'items') {
// } else if (change.path == 'items.splices') {
// } else {
// }
if (this.items && this.items.length) {
var uniqueData = [];
this.items.forEach(function (d) {
var val = d[this.column.key || this.column.field]
if (uniqueData.indexOf(val) == -1) {
//if(searchText && val.toString().toLowerCase().indexOf(searchText) == -1) return;
uniqueData.push(val);
}
}.bind(this));
this.set('_items', uniqueData.length ? uniqueData : []);
}
},
_filterItems: function (items, searchText) {
var search = searchText.toLowerCase();
return search.length ? items.filter(function (item) {
return item.toString().toLowerCase().indexOf(search) > -1;
}) : items;
},
_getSelectionState: function (item) {
return this._selectionState[item] ? true : false;
},
_toggleSelectAll: function (event) {
var state = event.target.checked;
var items = this.searchText.length ? this._filterItems(this._items, this.searchText) : this._items;
items.forEach(function (item) {
state ? this._selectionState[item] = state : delete this._selectionState[item];
}.bind(this));
this.set('_computeSelection', !this._computeSelection);
},
_toggleCheckboxSelection: function (event) {
var item = event.model.item;
if (event.target.checked) {
//this.set('_selectionState.' + item, true);
this._selectionState[item] = true;
} else {
delete this._selectionState[item];
this.set('_selectAllItems', false);
}
this.set('_computeSelection', !this._computeSelection);
},
_computeCheckBox: function (event) { // eslint-disable-line no-unused-vars
this.set('_selectAllItems', false);
},
_updateListSize: function (event) { // eslint-disable-line no-unused-vars
this.async(function () {
var lists = this.querySelectorAll('#list');
for (var i = 0, l = lists.length; i < l; i++) {
lists[i].notifyResize();
}
});
}
});
</script>