Skip to content
This repository was archived by the owner on Apr 1, 2022. It is now read-only.

Commit f678add

Browse files
author
Ken Berkeley
committed
[feature] colClass and colStyle can be applied to <th> and <td> at the same time
1 parent 99ad726 commit f678add

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

examples/src/Advanced/index.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,16 @@ export default {
3030
groupName: 'Normal',
3131
columns: [
3232
{ title: 'Email', field: 'email', visible: false, thComp: 'FilterTh', tdComp: 'Email' },
33-
{ title: 'Username', field: 'name', thComp: 'FilterTh' },
34-
{ title: 'Country', field: 'country', thComp: 'FilterTh' },
33+
{ title: 'Username', field: 'name', thComp: 'FilterTh', tdStyle: { fontStyle: 'italic' } },
34+
{ title: 'Country', field: 'country', thComp: 'FilterTh', thStyle: { fontWeight: 'normal' } },
3535
{ title: 'IP', field: 'ip', visible: false, tdComp: 'IP' }
3636
]
3737
}, {
3838
groupName: 'Sortable',
3939
columns: [
4040
{ title: 'User ID', field: 'uid', sort: true, visible: 'true', weight: 1 },
41-
{ title: 'Age', field: 'age', sort: true },
42-
{ title: 'Create time', field: 'createTime', sort: true,
43-
thClass: 'w-240', tdClass: 'w-240', thComp: 'CreatetimeTh', tdComp: 'CreatetimeTd' }
41+
{ title: 'Age', field: 'age', sort: true, thClass: 'text-info', tdClass: 'text-success' },
42+
{ title: 'Create time', field: 'createTime', sort: true, colClass: 'w-240', thComp: 'CreatetimeTh', tdComp: 'CreatetimeTd' }
4443
]
4544
}, {
4645
groupName: 'Extra (radio)',

lib/index.vue

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
<th v-if="selection && data.length" width="1em" key="th-multi">
1515
<multi-select :selection="selection" :rows="data" />
1616
</th>
17-
<th v-for="(column, idx) in columns$" :key="column.title || column.field || idx"
18-
:class="column.thClass" :style="column.thStyle">
17+
<th v-for="(column, idx) in columns$"
18+
:key="column.title || column.field || idx"
19+
:class="[column.colClass, column.thClass]"
20+
:style="[column.colStyle, column.thStyle]">
1921
<!-- table head component (thComp). `v-bind` here is just like spread operator in JSX -->
2022
<component v-if="column.thComp" :is="comp[column.thComp]" v-bind="$props"
2123
:column="column" :field="column.field" :title="column.title">
@@ -36,7 +38,9 @@
3638
<td v-if="selection" width="1em">
3739
<multi-select :selection="selection" :row="item" />
3840
</td>
39-
<td v-for="column in columns$" :class="column.tdClass" :style="column.tdStyle">
41+
<td v-for="column in columns$"
42+
:class="[column.colClass, column.tdClass]"
43+
:style="[column.colStyle, column.tdStyle]">
4044
<!-- table body component (tdComp) -->
4145
<component v-if="column.tdComp" :is="comp[column.tdComp]" v-bind="$props"
4246
:row="item" :field="column.field" :value="item[column.field]" :nested="item.__nested__">
@@ -61,7 +65,9 @@
6165
<td v-if="selection" width="1em"></td>
6266
<template v-for="(column, idx) in columns$">
6367
<!-- display the available fields only -->
64-
<td v-if="summary[column.field]" :class="column.tdClass" :style="column.tdStyle">
68+
<td v-if="summary[column.field]"
69+
:class="[column.colClass, column.tdClass]"
70+
:style="[column.colStyle, column.tdStyle]">
6571
<!-- table body component (tdComp) -->
6672
<component v-if="column.tdComp" :is="comp[column.tdComp]" v-bind="$props"
6773
:row="summary" :field="column.field" :value="summary[column.field]">
@@ -148,7 +154,7 @@ export default {
148154
// return columns$.map(col => ((col.weight = col.weight || 0), col)).sort((a, b) => b.weight - a.weight)
149155
},
150156
colspan () {
151-
return this.columns$.length + (+!!this.selection)
157+
return this.columns$.length + !!this.selection
152158
},
153159
data$ () {
154160
const { data, supportNested } = this

0 commit comments

Comments
 (0)