forked from Saulis/iron-data-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata-table-row-detail.html
100 lines (81 loc) · 2.67 KB
/
data-table-row-detail.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
<dom-module id="data-table-row-detail">
<template>
<style is="custom-style">
:host {
padding: 0 24px 0 24px;
display: flex;
align-items: center;
}
</style>
<content></content>
</template>
<script>
Polymer({
is: 'data-table-row-detail',
properties: {
bind: Object,
rowDetailTemplate: Object,
_instance: {
type: Object,
computed: '_templatize(rowDetailTemplate)'
}
},
behaviors: [
Polymer.Templatizer
],
observers: ['_bindData(_instance, bind)'],
ready: function() {
// cell is supposed to be placed outside the local dom of iron-data-table.
Polymer.StyleTransformer.dom(this, 'iron-data-table', this._scopeCssViaAttr, true);
},
_forwardParentProp: function(prop, value) {
if (this._instance) {
// TODO: this doesn't work for some reason. Calling this._instance.bind(..) manually from console
// works though. Most likely same issue that #8 has.
this._instance.bind({prop: value});
}
},
_forwardInstanceProp: function(inst, prop, value) {
if (prop === 'expanded' && inst.item && inst.__expanded__ !== value) {
var row = Polymer.dom(this).parentNode;
var table = Polymer.dom(row).parentNode;
table.fire(value ? 'item-expanded' : 'item-collapsed', {item: inst.item});
}
},
_forwardInstancePath: function(inst, path, value) {
if (path.indexOf('item') === 0) {
var row = Polymer.dom(this).parentNode;
var table = Polymer.dom(row).parentNode;
// instance.notifyPath above will call _forwardInstancePath recursively,
// so need to debounce to avoid firing the same event multiple times.
table.debounce('item-changed', function() {
// stripping 'item.' from path.
table.fire('item-changed', {item: inst.item, path: path.substring(5), value: value});
}.bind(this));
}
},
_bindData: function(instance, data) {
instance.bind(data);
},
_templatize: function(template) {
this._instanceProps = {
item: true,
index: true,
selected: true,
expanded: true
};
this.templatize(template);
var instance = this.stamp();
Polymer.dom(this).appendChild(instance.root);
Polymer.dom.flush();
return {
bind: function(data) {
for (var prop in data) {
instance[prop] = data[prop];
}
}
};
}
});
</script>
</dom-module>