-
Notifications
You must be signed in to change notification settings - Fork 17
/
paper-datatable-api-column.js
139 lines (133 loc) · 3.13 KB
/
paper-datatable-api-column.js
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
/* global customElements */
class DtPaperDatatableApiColumn
extends Polymer.mixinBehaviors([Polymer.Templatizer], Polymer.Element) {
static get is() {
return 'paper-datatable-api-column';
}
static get properties() {
return {
/**
* The name of the header for this column.
*/
header: String,
/**
* Property which will be available in data (throught paper-datatable-api).
*/
property: String,
/**
* If set, these other properties will be available in data (throught paper-datatable-api).
* Usefull to keep id of the object.
*/
otherProperties: {
type: Array,
value: [],
},
/**
* If true, the colum can be sort.
*/
sortable: {
type: Boolean,
value: false,
},
/**
* If true, the column can be draggable.
*/
draggableColumn: {
type: Boolean,
value: false,
},
/**
* If true, the column is hidden.
*/
hidden: {
type: Boolean,
value: false,
},
/**
* Current sort direction (asc or desc).
*/
sortDirection: String,
/**
* If true, the column is currently sorted.
*/
sorted: {
type: Boolean,
value: false,
},
/**
* If true, the column can be filtered.
*/
filter: {
type: Boolean,
value: false,
},
/**
* If true, a date picker is displayed when the column is sorted.
*/
date: {
type: Boolean,
value: false,
},
/**
* If true, the column can be hidden.
*/
hideable: {
type: Boolean,
value: false,
},
/**
* Position of the column in the table.
*/
position: Number,
activeFilter: {
type: Boolean,
value: false,
},
/**
* If true, the column apply the --paper-datatable-api-custom-td mixin.
*/
tdCustomStyle: {
type: Boolean,
value: false,
},
/**
* If setted, the choices are displayed in place of the paper-input (in filter mode)
*/
choices: Array,
};
}
constructor() {
super();
this.instances = [];
}
connectedCallback() {
if (!this.ctor) {
const props = {
__key__: true,
[this.header]: true,
[this.property]: true,
};
const template = this.querySelector('template');
this.ctor = Polymer.Templatize.templatize(template, this, {
instanceProps: props,
forwardHostProp(prop, value) {
this.instances.forEach((inst) => {
inst.forwardHostProp(prop, value);
});
},
});
}
}
/**
* Stamp the value in template (according to property).
*
* @property fillTemplate
* @param {String} value The value of the property.
*/
fillTemplate(value, otherValues) {
const instance = new this.ctor({ value, otherValues });
this.instances.push(instance);
return instance;
}
}
customElements.define(DtPaperDatatableApiColumn.is, DtPaperDatatableApiColumn);