Skip to content

Commit 1f6cb03

Browse files
authored
Merge pull request #51 from HC200ok/feature/header-customize
feature: add header slot
2 parents 1bc729a + e047980 commit 1f6cb03

File tree

2 files changed

+48
-23
lines changed

2 files changed

+48
-23
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"author": "HC200ok",
44
"description": "A customizable and easy-to-use data table component made with Vue.js 3.x.",
55
"private": false,
6-
"version": "1.2.20",
6+
"version": "1.2.25",
77
"types": "./types/main.d.ts",
88
"license": "MIT",
99
"files": [

src/components/DataTable.vue

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
'desc': header.sortable && header.sortType === 'desc',
3232
'asc': header.sortable && header.sortType === 'asc',
3333
'fixed': header.fixed,
34-
'hasShadow': header.value === lastFixedColumn,
34+
'has-shadow': header.value === lastFixedColumn,
35+
'no-padding': noThPadding
3536
}"
3637
:style="getFixedDistance(header.value)"
37-
@click="(header.sortable && header.sortType) ? updateSortField(header.value, header.sortType) : null"
3838
>
3939
<MutipleSelectCheckBox
4040
v-if="header.text === 'checkbox'"
@@ -44,16 +44,25 @@
4444
/>
4545
<span
4646
v-else
47-
class="header-text__wrapper"
47+
class="header-item"
4848
>
49-
<span class="header-text">
49+
<slot
50+
v-if="slots[`header-${header.value}`]"
51+
:name="`header-${header.value}`"
52+
v-bind="header"
53+
/>
54+
<span
55+
v-else
56+
class="header-text"
57+
>
5058
{{ header.text }}
5159
</span>
5260
<i
5361
v-if="header.sortable"
5462
:key="header.sortType ? header.sortType : 'none'"
5563
class="sortType-icon"
5664
:class="{'desc': header.sortType === 'desc'}"
65+
@click.stop="(header.sortable && header.sortType) ? updateSortField(header.value, header.sortType) : null"
5766
></i>
5867
</span>
5968
</th>
@@ -77,11 +86,14 @@
7786
v-for="(column, i) in headerColumns"
7887
:key="i"
7988
:style="getFixedDistance(column, 'td')"
80-
:class="{'hasShadow': column === lastFixedColumn}"
89+
:class="{
90+
'has-shadow': column === lastFixedColumn,
91+
'no-padding': noTdPadding,
92+
}"
8193
>
8294
<slot
83-
v-if="slots[column]"
84-
:name="column"
95+
v-if="slots[`item-${column}`]"
96+
:name="`item-${column}`"
8597
v-bind="item"
8698
/>
8799
<template v-else-if="column === 'checkbox'">
@@ -377,6 +389,14 @@ const props = defineProps({
377389
type: Boolean,
378390
default: false,
379391
},
392+
noThPadding: {
393+
type: Boolean,
394+
default: false,
395+
},
396+
noTdPadding: {
397+
type: Boolean,
398+
default: false,
399+
},
380400
});
381401
382402
const {
@@ -402,6 +422,8 @@ const tableHeightPx = computed(() => (props.tableHeight ? `${props.tableHeight}p
402422
const minHeightPx = computed(() => `${rowHeight.value * 5}px`);
403423
const sortTypeIconSize = computed(() => Math.round(props.tableFontSize / 2.5));
404424
const sortTypeIconSizePx = computed(() => `${sortTypeIconSize.value}px`);
425+
const sortClickAreaSizePx = computed(() => `${sortTypeIconSize.value * 5}px`);
426+
const sortClickAreaOffsetSizePx = computed(() => `-${sortTypeIconSize.value * 2.5}px`);
405427
const sortTypeIconMargin = computed(() => Math.round(sortTypeIconSize.value));
406428
const sortTypeAscIconMarginTopPx = computed(() => `-${sortTypeIconMargin.value}px`);
407429
const sortTypeDescIconMarginTopPx = computed(() => `${sortTypeIconMargin.value}px`);
@@ -893,7 +915,6 @@ defineExpose({
893915
prevPage,
894916
updatePage,
895917
});
896-
897918
</script>
898919

899920
<style lang="scss" scoped>
@@ -914,14 +935,14 @@ defineExpose({
914935
&::-webkit-scrollbar-track
915936
{
916937
border-radius: 10px;
917-
background-color: #fff;
938+
background-color: v-bind(rowBackgroundColor);
918939
}
919940
920941
&::-webkit-scrollbar
921942
{
922943
width: 7px;
923944
height: 7px;
924-
background-color: #fff;
945+
background-color: v-bind(rowBackgroundColor);
925946
}
926947
927948
&::-webkit-scrollbar-thumb
@@ -931,7 +952,7 @@ defineExpose({
931952
}
932953
933954
&.show-shadow {
934-
th.hasShadow, td.hasShadow {
955+
th.has-shadow, td.has-shadow {
935956
&::after {
936957
box-shadow: inset 6px 0 5px -3px rgb(0 0 0 / 20%)
937958
}
@@ -1013,7 +1034,10 @@ defineExpose({
10131034
text-align: left;
10141035
padding: 0px 10px;
10151036
}
1016-
th.hasShadow, td.hasShadow {
1037+
th.no-padding, td.no-padding {
1038+
padding: 0px;
1039+
}
1040+
th.has-shadow, td.has-shadow {
10171041
&::after {
10181042
pointer-events: none;
10191043
content: "";
@@ -1041,7 +1065,7 @@ defineExpose({
10411065
color: v-bind(headerFontColor);
10421066
position: relative;
10431067
background-color: v-bind(headerBackgroundColor);
1044-
.header-text__wrapper {
1068+
.header-item {
10451069
display: flex;
10461070
align-items: center;
10471071
height: v-bind(fontSizePx);
@@ -1062,7 +1086,17 @@ defineExpose({
10621086
display: inline-block;
10631087
height: 0;
10641088
width: 0;
1089+
position: relative;
10651090
border-bottom-color: v-bind(headerFontColor);
1091+
&::after {
1092+
content: "";
1093+
display: block;
1094+
width: v-bind(sortClickAreaSizePx);
1095+
height: v-bind(sortClickAreaSizePx);
1096+
position: absolute;
1097+
left: v-bind(sortClickAreaOffsetSizePx);
1098+
top: v-bind(sortClickAreaOffsetSizePx);;
1099+
}
10661100
}
10671101
10681102
&.none {
@@ -1083,15 +1117,6 @@ defineExpose({
10831117
}
10841118
}
10851119
}
1086-
1087-
.sortType-icon {
1088-
display: inline-block;
1089-
width: v-bind(fontSizePx);
1090-
height: v-bind(fontSizePx);
1091-
&.desc {
1092-
transform: rotate(180deg);
1093-
}
1094-
}
10951120
}
10961121
}
10971122
tbody {

0 commit comments

Comments
 (0)