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
import PropTypes from '../../_util/vue-types';
import TableHeaderRow from './TableHeaderRow';
function getHeaderRows(columns) {
var currentRow = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var rows = arguments[2];
rows = rows || [];
rows[currentRow] = rows[currentRow] || [];
columns.forEach(function (column) {
if (column.rowSpan && rows.length < column.rowSpan) {
while (rows.length < column.rowSpan) {
rows.push([]);
}
}
var cell = {
key: column.key,
className: column.className || column['class'] || '',
children: column.title,
column: column
};
if (column.children) {
getHeaderRows(column.children, currentRow + 1, rows);
}
if ('colSpan' in column) {
cell.colSpan = column.colSpan;
}
if ('rowSpan' in column) {
cell.rowSpan = column.rowSpan;
}
if (cell.colSpan !== 0) {
rows[currentRow].push(cell);
}
});
return rows.filter(function (row) {
return row.length > 0;
});
}
export default {
name: 'TableHeader',
props: {
fixed: PropTypes.string,
columns: PropTypes.array.isRequired,
expander: PropTypes.object.isRequired
},
inject: {
table: { 'default': function _default() {
return {};
} }
},
render: function render() {
var h = arguments[0];
var _table = this.table,
components = _table.sComponents,
prefixCls = _table.prefixCls,
showHeader = _table.showHeader,
customHeaderRow = _table.customHeaderRow;
var expander = this.expander,
columns = this.columns,
fixed = this.fixed;
if (!showHeader) {
return null;
}
var rows = getHeaderRows(columns);
expander.renderExpandIndentCell(rows, fixed);
var HeaderWrapper = components.header.wrapper;
return h(
HeaderWrapper,
{ 'class': prefixCls + '-thead' },
[rows.map(function (row, index) {
return h(TableHeaderRow, {
attrs: {
prefixCls: prefixCls,
index: index,
fixed: fixed,
columns: columns,
rows: rows,
row: row,
components: components,
customHeaderRow: customHeaderRow
},
key: index });
})]
);
}
};