Skip to content

Commit 55bddd1

Browse files
committed
Improvement - VueUiTable - Add config option to show/hide export menu; add page-change event #248
1 parent 7b00e2a commit 55bddd1

File tree

4 files changed

+72
-9
lines changed

4 files changed

+72
-9
lines changed

TestingArena/ArenaVueUiTable.vue

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,41 @@ onMounted(() => {
219219
}, 3000)
220220
})
221221
222+
const config = ref({
223+
style: {
224+
exportMenu: {
225+
show: true,
226+
}
227+
}
228+
})
229+
230+
function pageChange(data) {
231+
console.log(data)
232+
}
233+
234+
const table = ref(null);
235+
236+
function nav(dir) {
237+
if (table.value) {
238+
table.value.navigate(dir)
239+
}
240+
}
241+
242+
onMounted(() => {
243+
if (table.value) {
244+
console.log(table.value.getCurrentPageData())
245+
}
246+
})
247+
222248
</script>
223249

224250
<template>
251+
<button @click="nav('previous')">PREV</button>
252+
<button @click="nav('next')">NEXT</button>
225253
<div style="background: white">
226-
<LocalVueUiTable :dataset="dataset"/>
227-
<LocalVueDataUi component="VueUiTable" :dataset="dataset"/>
228-
<VueUiTable :dataset="dataset"/>
229-
<VueDataUi component="VueUiTable" :dataset="dataset"/>
254+
<LocalVueUiTable ref="table" :dataset="dataset" :config="config" @page-change="pageChange"/>
255+
<LocalVueDataUi component="VueUiTable" :dataset="dataset" :config="config"/>
256+
<VueUiTable :dataset="dataset" :config="config"/>
257+
<VueDataUi component="VueUiTable" :dataset="dataset" :config="config"/>
230258
</div>
231259
</template>

src/components/vue-ui-table.vue

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="vue-ui-table-main" :style="`font-family: ${FINAL_CONFIG.fontFamily}`">
3-
<div class="vue-ui-table-export-hub">
3+
<div class="vue-ui-table-export-hub" v-if="FINAL_CONFIG.style.exportMenu.show">
44
<button @click="isExportRequest = !isExportRequest" v-html="icons.export"
55
:style="`background:${FINAL_CONFIG.style.exportMenu.backgroundColor};color:${FINAL_CONFIG.style.exportMenu.color}`" />
66
<div class="vue-ui-table-export-hub-dropdown" :data-is-open="isExportRequest || 'false'"
@@ -40,7 +40,10 @@
4040
<div class="vue-ui-table__wrapper" :style="`max-height:${FINAL_CONFIG.maxHeight}px`" ref="tableWrapper">
4141
<table class="vue-ui-table">
4242
<!-- TABLE HEAD -->
43-
<thead id="tableHead">
43+
<thead id="tableHead" class="vue-ui-table__head" :style="{
44+
background: FINAL_CONFIG.style.th.backgroundColor,
45+
boxShadow: `-1px 0 0 ${FINAL_CONFIG.style.th.backgroundColor}`
46+
}">
4447
<!-- HEADERS -->
4548
<tr>
4649
<th class="invisible-cell"></th>
@@ -395,7 +398,7 @@
395398
{{ FINAL_CONFIG.translations.totalRows }} : {{ dataset.body.length }} |
396399
{{ FINAL_CONFIG.translations.paginatorLabel }} :
397400
<select id="paginatorSelector" v-model.number="itemsPerPage" v-if="bodyCopy.length > 10"
398-
@change="resetSelection"
401+
@change="resetSelection(); onPageChange();"
399402
:style="`background:${FINAL_CONFIG.style.inputs.backgroundColor};color:${FINAL_CONFIG.style.inputs.color};border:${FINAL_CONFIG.style.inputs.border}`">
400403
<template v-for="(option, i) in paginatorOptions">
401404
<option :key="`paginator_option_${i}`"
@@ -572,6 +575,7 @@ export default {
572575
}
573576
},
574577
components: { VueUiXy, VueUiDonut },
578+
emits: ['page-change'],
575579
data() {
576580
const uid = `vue-ui-table-${Math.random()}`;
577581
return {
@@ -1245,15 +1249,35 @@ export default {
12451249
return this.multiselects[index].length === this.getDropdownOptions(index).length;
12461250
}
12471251
},
1252+
getCurrentPageData() {
1253+
return {
1254+
totalPages: this.pages.length,
1255+
itemsPerPage: this.itemsPerPage,
1256+
currentPage: this.currentPage,
1257+
currentPageData: this.visibleRows.map(r => r.td)
1258+
}
1259+
},
1260+
onPageChange() {
1261+
this.$emit('page-change', this.getCurrentPageData());
1262+
},
12481263
navigate(direction) {
12491264
this.resetSelection();
12501265
if (direction === 'next' && this.currentPage < this.pages.length) {
1266+
if (this.currentPage + 1 > this.pages.length - 1) {
1267+
return;
1268+
}
12511269
this.currentPage += 1;
12521270
} else if (direction === 'previous' && this.currentPage >= 1) {
12531271
this.currentPage -= 1;
12541272
} else {
1273+
if (direction - 1 < 0 || direction > this.pages.length || direction === 'previous') {
1274+
return;
1275+
}
12551276
this.currentPage = direction - 1;
12561277
}
1278+
1279+
this.onPageChange();
1280+
12571281
const table = this.$refs.tableWrapper;
12581282
table.scrollTo({
12591283
top: 0,
@@ -1700,6 +1724,7 @@ export default {
17001724
} else {
17011725
this.currentPage = Number(event.target.value);
17021726
}
1727+
this.onPageChange();
17031728
},
17041729
17051730
// DONUTS
@@ -2176,6 +2201,7 @@ button.th-reset:not(:disabled) {
21762201
}
21772202
21782203
.vue-ui-table-main td.vue-ui-table-td-iteration {
2204+
min-width: 48px;
21792205
font-size: 12px;
21802206
font-variant-numeric: tabular-nums;
21812207
text-align: right;
@@ -2310,9 +2336,9 @@ button.th-reset:not(:disabled) {
23102336
}
23112337
23122338
.vue-ui-table-main .vue-ui-table-export-hub {
2313-
left: 5px;
2339+
left: 20px;
23142340
position: absolute;
2315-
top: 0;
2341+
top: 3px;
23162342
z-index: 1001;
23172343
}
23182344

src/useConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5327,6 +5327,7 @@ export function useConfig() {
53275327
}
53285328
},
53295329
exportMenu: {
5330+
show: true,
53305331
backgroundColor: COLOR_GREY_LIGHT,
53315332
color: COLOR_BLACK,
53325333
buttons: {

types/vue-data-ui.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5554,6 +5554,7 @@ declare module "vue-data-ui" {
55545554
};
55555555
};
55565556
exportMenu?: {
5557+
show?: boolean;
55575558
backgroundColor?: string;
55585559
color?: string;
55595560
buttons?: {
@@ -5646,6 +5647,13 @@ declare module "vue-data-ui" {
56465647
useChart?: boolean;
56475648
};
56485649

5650+
export type VueUiTablePageChangeEvent = {
5651+
totalPages: number;
5652+
itemsPerPage: number;
5653+
currentPage: number;
5654+
currentPageData: Array<Array<string | number>>
5655+
}
5656+
56495657
export const VueUiTable: DefineComponent<{
56505658
config?: VueUiTableConfig;
56515659
dataset: VueUiTableDataset;

0 commit comments

Comments
 (0)