Skip to content

Commit 3ff8b14

Browse files
committed
feat: CTable added headVariant prop, added V-Html to table headers
1 parent 26c5699 commit 3ff8b14

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/components/Table/CTable.vue

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,22 @@
3232
<slot name="overTable"/>
3333
<div :class="notResponsive ? '' : 'table-responsive'" class="position-relative">
3434
<table :class="tableClasses">
35-
<thead >
35+
<thead :class="headVariant ? `thead-${headVariant}` : ''">
3636
<tr>
3737
<th v-if="indexCol" style="width:40px"></th>
3838
<template v-for="(name, index) in columnNames">
3939
<th @click="changeSort(rawColumnNames[index], index)"
4040
:class="headerClass(index)"
4141
:style="headerStyles(index)"
4242
>
43-
<slot :name="`${rawColumnNames[index]}-header`">
44-
{{name}}
45-
</slot>
46-
<slot v-if="!noSorting && sortable(index)" name="sorting-icon" :state="getIconState(index)">
47-
<i :class="iconClasses(index)"></i>
48-
</slot>
43+
<slot v-if="$slots[`${rawColumnNames[index]}-header`]"
44+
:name="`${rawColumnNames[index]}-header`"
45+
>
46+
</slot>
47+
<div v-else v-html="name" class="d-inline"></div>
48+
<slot v-if="!noSorting && sortable(index)" name="sorting-icon" :state="getIconState(index)">
49+
<i :class="iconClasses(index)"></i>
50+
</slot>
4951
</th>
5052
</template>
5153
</tr>
@@ -198,15 +200,19 @@ export default {
198200
},
199201
defaultTableFilter: String,
200202
defaultColumnFilter: Object,
201-
loading: Boolean
203+
loading: Boolean,
204+
headVariant: {
205+
type: String,
206+
validator: val => ['light', 'dark'].includes(val)
207+
}
202208
},
203209
data () {
204210
return {
205211
tableFilter: this.defaultTableFilter,
206212
columnFilter: this.defaultColumnFilter || {},
207213
sorter: { name: this.defaultSorter.name, direction: this.defaultSorter.direction },
208214
firstItemIndex: 0,
209-
page: this.activePage || 2,
215+
page: this.activePage || 1,
210216
pages: 0,
211217
perPageItems: this.perPage,
212218
passedItems: this.items
@@ -235,8 +241,12 @@ export default {
235241
const n = this.sorter.name
236242
return this.tableFiltered.sort((a,b) => {
237243
//escape html
238-
const c = a[n] ? a[n].replace(/<(?:.|\n)*?>/gm, '') : ''
239-
const d = b[n] ? b[n].replace(/<(?:.|\n)*?>/gm, '') : ''
244+
let c = typeof a[n] === 'string' ? a[n].replace(/<(?:.|\n)*?>/gm, '') : a[n]
245+
let d = typeof b[n] === 'string' ? b[n].replace(/<(?:.|\n)*?>/gm, '') : b[n]
246+
if (typeof c !== typeof d) {
247+
c = String(c)
248+
d = String(d)
249+
}
240250
return (c > d) ? 1 * flip : ((d > c) ? -1 * flip : 0)
241251
})
242252
},

0 commit comments

Comments
 (0)