Skip to content

Commit 7b55f7a

Browse files
committed
feat: Refactor table header component
1 parent 5f96301 commit 7b55f7a

File tree

2 files changed

+47
-72
lines changed

2 files changed

+47
-72
lines changed

src/components/table-col-group.vue

-34
This file was deleted.

src/components/table-header.js

+47-38
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default {
88
default: () => []
99
},
1010

11+
border: [Boolean],
1112
sort: {}
1213
},
1314

@@ -18,7 +19,7 @@ export default {
1819
},
1920

2021
methods: {
21-
getColumnClass (col) {
22+
getColumnClass (col, index) {
2223
const cls = ['v2-table__cell', 'v2-table__column-cell'];
2324

2425
if (col.sortable && !col.type) {
@@ -40,11 +41,7 @@ export default {
4041

4142
getColStyle (col) {
4243
const style = {};
43-
44-
style.width = !isNaN(parseInt(col.width)) ? '90px' : `${parseInt(col.width, 10)}px`;
45-
style.height = !isNaN(parseInt(this.table.colHeight, 10)) ? '40px' : `${parseInt(this.table.colHeight, 10)}px`;
46-
47-
// style.textAlign = ['left', 'center', 'right'].indexOf(col.align) > -1 ? col.align : 'center';
44+
style.width = `${col.$realWidth}px`;
4845

4946
return style;
5047
},
@@ -60,40 +57,52 @@ export default {
6057

6158
render (h) {
6259
return (
63-
<div class='v2-table__table-thead'>
64-
<div class='v2-table__header-row'>
60+
<table
61+
class={{ 'v2-table__header': true, 'v2-table__border': this.border, 'v2-table__header-border': this.border }}
62+
cellspacing='0'
63+
border='0'
64+
cellpadding='0'>
65+
<colgroup>
6566
{
66-
this.columns.map((column, index) => {
67-
return (
68-
<div key={index}
69-
onClick={this.changeSortRule(column)}
70-
class={ this.getColumnClass(column) }
71-
style={ this.getColStyle(column) }
72-
>
73-
{
74-
typeof column.renderHeader === 'function'
75-
? column.renderHeader.call(this._renderProxy, h, { column, index })
76-
: column.label
77-
}
78-
{
79-
column.sortable && !column.type
80-
? <span class='v2-table__caret-wrapper'>
81-
<i class='v2-table__sort-caret ascending-caret'></i>
82-
<i class='v2-table__sort-caret descending-caret'></i>
83-
</span>
84-
: ''
85-
}
86-
{
87-
column.type === 'selection'
88-
? <check-box cur-row-index={-1}></check-box>
89-
: ''
90-
}
91-
</div>
92-
);
93-
})
67+
this.columns.map(column => <col style={ this.getColStyle(column) } />)
9468
}
95-
</div>
96-
</div>
69+
</colgroup>
70+
<thead>
71+
<tr>
72+
{
73+
this.columns.map((column, index) => {
74+
return (
75+
<th key={index}
76+
onClick={this.changeSortRule(column)}
77+
class={ this.getColumnClass(column, index) }
78+
style= {{ height: this.table.colHeight + 'px' }}
79+
colspan='1'
80+
rowspan='1'>
81+
{
82+
typeof column.renderHeader === 'function'
83+
? column.renderHeader.call(this._renderProxy, h, { column, index })
84+
: column.label
85+
}
86+
{
87+
column.sortable && !column.type
88+
? <span class='v2-table__caret-wrapper'>
89+
<i class='v2-table__sort-caret ascending-caret'></i>
90+
<i class='v2-table__sort-caret descending-caret'></i>
91+
</span>
92+
: ''
93+
}
94+
{
95+
column.type === 'selection'
96+
? <check-box cur-row-index={-1}></check-box>
97+
: ''
98+
}
99+
</th>
100+
);
101+
})
102+
}
103+
</tr>
104+
</thead>
105+
</table>
97106
);
98107
}
99108
};

0 commit comments

Comments
 (0)