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
/* eslint-disable no-console,func-names,react/no-multi-comp */
import Table from '../index';
import '../assets/index.less';
var tableData = [{ key: 0, a: '123' }, { key: 1, a: 'cdd', b: 'edd' }, { key: 2, a: '1333', c: 'eee', d: 2 }];
export default {
data: function data() {
return {
data: tableData,
expandedRowKeys: [],
expandIconAsCell: true,
expandRowByClick: false,
columns: [{ title: 'title 1', dataIndex: 'a', key: 'a', width: 100 }, { title: 'title 2', dataIndex: 'b', key: 'b', width: 100 }, { title: 'title 3', dataIndex: 'c', key: 'c', width: 200 }, { title: 'Operation', dataIndex: '', key: 'x', customRender: this.renderAction }]
};
},
methods: {
onExpand: function onExpand(expanded, record) {
console.log('onExpand', expanded, record);
},
onExpandedRowsChange: function onExpandedRowsChange(rows) {
this.expandedRowKeys = rows;
},
onExpandIconAsCellChange: function onExpandIconAsCellChange(e) {
this.expandIconAsCell = e.target.checked;
},
onExpandRowByClickChange: function onExpandRowByClickChange(e) {
this.expandRowByClick = e.target.checked;
},
toggleButton: function toggleButton() {
var _this = this;
var h = this.$createElement;
if (this.expandedRowKeys.length) {
var closeAll = function closeAll() {
_this.expandedRowKeys = [];
};
return h(
'button',
{
on: {
'click': closeAll
}
},
['Close All']
);
}
var openAll = function openAll() {
_this.expandedRowKeys = [0, 1, 2];
};
return h(
'button',
{
on: {
'click': openAll
}
},
['Expand All']
);
},
remove: function remove(index) {
var data = this.data;
data.splice(index, 1);
this.data = data;
},
renderAction: function renderAction(o, row, index) {
var _this2 = this;
var h = this.$createElement;
return h(
'a',
{
attrs: { href: '#' },
on: {
'click': function click() {
return _this2.remove(index);
}
}
},
['Delete']
);
}
},
render: function render() {
var h = arguments[0];
var expandIconAsCell = this.expandIconAsCell,
expandRowByClick = this.expandRowByClick,
expandedRowKeys = this.expandedRowKeys,
data = this.data;
return h('div', [h('h2', ['expandedRowRender']), h('div', [this.toggleButton(), h('span', { style: { display: 'inline-block', width: '20px' } }), h('input', {
attrs: {
type: 'checkbox'
},
domProps: {
'checked': expandIconAsCell
},
on: {
'change': this.onExpandIconAsCellChange
}
}), 'expandIconAsCell', h('span', { style: { display: 'inline-block', width: '20px' } }), h('input', {
attrs: {
type: 'checkbox'
},
domProps: {
'checked': expandRowByClick
},
on: {
'change': this.onExpandRowByClickChange
}
}), 'expandRowByClick', h(Table, {
attrs: {
columns: this.columns,
expandIconAsCell: expandIconAsCell,
expandRowByClick: expandRowByClick,
expandedRowRender: function expandedRowRender(record, index, indent, expanded) {
return expanded ? h('p', ['extra: ', record.a]) : null;
},
expandedRowKeys: expandedRowKeys,
data: data
},
on: {
'expandedRowsChange': this.onExpandedRowsChange,
'expand': this.onExpand
}
})])]);
}
};