Skip to content

Commit 52a7c21

Browse files
committed
New feature - VueUiTable - Add optional title #255
1 parent 87a8939 commit 52a7c21

File tree

4 files changed

+80
-3
lines changed

4 files changed

+80
-3
lines changed

TestingArena/ArenaVueUiTable.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,22 @@ onMounted(() => {
241241
242242
const config = ref({
243243
style: {
244+
title: {
245+
text: 'Some title that can be long',
246+
color: '#FF0000',
247+
fontSize: 18,
248+
bold: false,
249+
textAlign: 'left',
250+
paddingLeft: 12,
251+
paddingRight: 0,
252+
backgroundColor: '#00FF00',
253+
subtitle: {
254+
text: 'Some subtitle',
255+
fontSize: 12,
256+
color: '#0000FF',
257+
bold: true,
258+
}
259+
},
244260
exportMenu: {
245261
show: true,
246262
}

src/components/vue-ui-table.vue

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<div class="vue-ui-table-main" :style="`font-family: ${FINAL_CONFIG.fontFamily}`">
3-
<div class="vue-ui-table-export-hub" v-if="FINAL_CONFIG.style.exportMenu.show">
3+
<div class="vue-ui-table-export-hub"
4+
:style="{ top: exportButtonTop + 'px' }" v-if="FINAL_CONFIG.style.exportMenu.show">
45
<button @click="isExportRequest = !isExportRequest" v-html="icons.export"
56
:style="`background:${FINAL_CONFIG.style.exportMenu.backgroundColor};color:${FINAL_CONFIG.style.exportMenu.color}`" />
67
<div class="vue-ui-table-export-hub-dropdown" :data-is-open="isExportRequest || 'false'"
@@ -48,10 +49,45 @@
4849
</div>
4950
<div class="vue-ui-table__wrapper" :style="`max-height:${FINAL_CONFIG.maxHeight}px`" ref="tableWrapper">
5051
<table class="vue-ui-table">
52+
<caption
53+
class="vue-ui-table__caption"
54+
ref="tableCaption"
55+
v-if="FINAL_CONFIG.style.title.text"
56+
:style="{
57+
textAlign: FINAL_CONFIG.style.title.textAlign,
58+
paddingLeft: FINAL_CONFIG.style.title.paddingLeft + 'px',
59+
paddingRight: FINAL_CONFIG.style.title.paddingRight + 'px',
60+
backgroundColor: FINAL_CONFIG.style.title.backgroundColor,
61+
boxShadow: `${FINAL_CONFIG.style.title.backgroundColor} -1px 0px 0px 0px`
62+
}"
63+
>
64+
<span
65+
:style="{
66+
fontSize: FINAL_CONFIG.style.title.fontSize + 'px',
67+
fontWeight: FINAL_CONFIG.style.title.bold ? 'bold' : 'normal',
68+
color: FINAL_CONFIG.style.title.color
69+
}"
70+
>
71+
{{ FINAL_CONFIG.style.title.text }}
72+
</span>
73+
<template v-if="FINAL_CONFIG.style.title.subtitle.text">
74+
<br>
75+
<span
76+
:style="{
77+
fontSize: FINAL_CONFIG.style.title.subtitle.fontSize,
78+
fontWeight: FINAL_CONFIG.style.title.subtitle.bold ? 'bold' : 'normal',
79+
color: FINAL_CONFIG.style.title.subtitle.color
80+
}"
81+
>
82+
{{ FINAL_CONFIG.style.title.subtitle.text }}
83+
</span>
84+
</template>
85+
</caption>
5186
<!-- TABLE HEAD -->
5287
<thead id="tableHead" class="vue-ui-table__head" :style="{
5388
background: FINAL_CONFIG.style.th.backgroundColor,
54-
boxShadow: `-1px 0 0 ${FINAL_CONFIG.style.th.backgroundColor}`
89+
boxShadow: `-1px 0 0 ${FINAL_CONFIG.style.th.backgroundColor}`,
90+
top: exportButtonTop - 3 + 'px'
5591
}">
5692
<!-- HEADERS -->
5793
<tr>
@@ -573,6 +609,7 @@ import { useConfig } from "../useConfig";
573609
import VueUiXy from "./vue-ui-xy.vue";
574610
import VueUiDonut from "./vue-ui-donut.vue";
575611
import BaseIcon from "../atoms/BaseIcon.vue";
612+
import { computed, ref } from "vue";
576613
577614
export default {
578615
name: "vue-ui-table",
@@ -691,6 +728,19 @@ export default {
691728
filename: '',
692729
}
693730
},
731+
setup() {
732+
const tableCaption = ref(null);
733+
734+
const exportButtonTop = computed(() => {
735+
if (!tableCaption.value) return 3;
736+
return tableCaption.value.getBoundingClientRect().height + 3;
737+
});
738+
739+
return {
740+
tableCaption,
741+
exportButtonTop
742+
}
743+
},
694744
mounted() {
695745
if (this.dataset.header.length === 0) {
696746
throw new Error("vue-ui-table error: missing header data.\nProvide an array of objects of type:\n{\n name: string;\n type: string; ('text' | 'numeric' | 'date')\n average: boolean;\n decimals: number | undefined;\n sum: boolean;\n isSort:boolean;\n isSearch: boolean;\n isMultiselect: boolean;\n isPercentage: boolean;\n percentageTo: string; (or '')\n}");
@@ -1866,6 +1916,13 @@ export default {
18661916
top: 0;
18671917
}
18681918
1919+
.vue-ui-table-main caption {
1920+
caption-side: top;
1921+
position: sticky;
1922+
top: 0;
1923+
z-index: 2;
1924+
}
1925+
18691926
.vue-ui-table {
18701927
width: 100%;
18711928
position: relative;
@@ -2396,7 +2453,6 @@ button.th-reset:not(:disabled) {
23962453
.vue-ui-table-main .vue-ui-table-export-hub {
23972454
left: 20px;
23982455
position: absolute;
2399-
top: 3px;
24002456
z-index: 1001;
24012457
}
24022458

src/useConfig.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5284,6 +5284,10 @@ export function useConfig() {
52845284
maxHeight: 500,
52855285
rowsPerPage: 25,
52865286
style: {
5287+
title: {
5288+
...TITLE,
5289+
backgroundColor: COLOR_WHITE,
5290+
},
52875291
th: {
52885292
backgroundColor: COLOR_GREY_LIGHT,
52895293
color: COLOR_BLACK,

types/vue-data-ui.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5566,6 +5566,7 @@ declare module "vue-data-ui" {
55665566
maxHeight?: number;
55675567
rowsPerPage?: number;
55685568
style?: {
5569+
title?: ChartTitle & { backgroundColor?: string };
55695570
th?: ChartTableCell & {
55705571
selected?: {
55715572
backgroundColor?: string;

0 commit comments

Comments
 (0)