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
import PropTypes from '../../_util/vue-types';
import ExpandIcon from './ExpandIcon';
import BaseMixin from '../../_util/BaseMixin';
import { connect } from '../../_util/store';
var ExpandableRow = {
mixins: [BaseMixin],
name: 'ExpandableRow',
props: {
prefixCls: PropTypes.string.isRequired,
rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
fixed: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
record: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
indentSize: PropTypes.number,
needIndentSpaced: PropTypes.bool.isRequired,
expandRowByClick: PropTypes.bool,
expanded: PropTypes.bool.isRequired,
expandIconAsCell: PropTypes.bool,
expandIconColumnIndex: PropTypes.number,
childrenColumnName: PropTypes.string,
expandedRowRender: PropTypes.func,
expandIcon: PropTypes.func
// onExpandedChange: PropTypes.func.isRequired,
// onRowClick: PropTypes.func,
// children: PropTypes.func.isRequired,
},
beforeDestroy: function beforeDestroy() {
this.handleDestroy();
},
methods: {
hasExpandIcon: function hasExpandIcon(columnIndex) {
var expandRowByClick = this.expandRowByClick;
return !this.tempExpandIconAsCell && !expandRowByClick && columnIndex === this.tempExpandIconColumnIndex;
},
handleExpandChange: function handleExpandChange(record, event) {
var expanded = this.expanded,
rowKey = this.rowKey;
this.__emit('expandedChange', !expanded, record, event, rowKey);
},
handleDestroy: function handleDestroy() {
var rowKey = this.rowKey,
record = this.record;
this.__emit('expandedChange', false, record, null, rowKey, true);
},
handleRowClick: function handleRowClick(record, index, event) {
var expandRowByClick = this.expandRowByClick;
if (expandRowByClick) {
this.handleExpandChange(record, event);
}
this.__emit('rowClick', record, index, event);
},
renderExpandIcon: function renderExpandIcon() {
var h = this.$createElement;
var prefixCls = this.prefixCls,
expanded = this.expanded,
record = this.record,
needIndentSpaced = this.needIndentSpaced,
expandIcon = this.expandIcon;
if (expandIcon) {
return expandIcon({
prefixCls: prefixCls,
expanded: expanded,
record: record,
needIndentSpaced: needIndentSpaced,
expandable: this.expandable,
onExpand: this.handleExpandChange
});
}
return h(ExpandIcon, {
attrs: {
expandable: this.expandable,
prefixCls: prefixCls,
needIndentSpaced: needIndentSpaced,
expanded: expanded,
record: record
},
on: {
'expand': this.handleExpandChange
}
});
},
renderExpandIconCell: function renderExpandIconCell(cells) {
var h = this.$createElement;
if (!this.tempExpandIconAsCell) {
return;
}
var prefixCls = this.prefixCls;
cells.push(h(
'td',
{ 'class': prefixCls + '-expand-icon-cell', key: 'rc-table-expand-icon-cell' },
[this.renderExpandIcon()]
));
}
},
render: function render() {
var childrenColumnName = this.childrenColumnName,
expandedRowRender = this.expandedRowRender,
indentSize = this.indentSize,
record = this.record,
fixed = this.fixed,
$scopedSlots = this.$scopedSlots,
expanded = this.expanded;
this.tempExpandIconAsCell = fixed !== 'right' ? this.expandIconAsCell : false;
this.tempExpandIconColumnIndex = fixed !== 'right' ? this.expandIconColumnIndex : -1;
var childrenData = record[childrenColumnName];
this.expandable = !!(childrenData || expandedRowRender);
var expandableRowProps = {
props: {
indentSize: indentSize,
expanded: expanded, // not used in TableRow, but it's required to re-render TableRow when `expanded` changes
hasExpandIcon: this.hasExpandIcon,
renderExpandIcon: this.renderExpandIcon,
renderExpandIconCell: this.renderExpandIconCell
},
on: {
rowClick: this.handleRowClick
}
};
return $scopedSlots['default'] && $scopedSlots['default'](expandableRowProps);
}
};
export default connect(function (_ref, _ref2) {
var expandedRowKeys = _ref.expandedRowKeys;
var rowKey = _ref2.rowKey;
return {
expanded: !!~expandedRowKeys.indexOf(rowKey)
};
})(ExpandableRow);