From 41deb8217415e2097d1ac25b7b6150a65102731d Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 8 Jul 2024 13:23:42 +0200 Subject: [PATCH] feat(VnTable): add visibleColumns --- src/components/VnTable/VnTable.vue | 41 +++-- src/components/VnTable/VnVisibleColumn.vue | 181 +++++++++++++++++++++ 2 files changed, 205 insertions(+), 17 deletions(-) create mode 100644 src/components/VnTable/VnVisibleColumn.vue diff --git a/src/components/VnTable/VnTable.vue b/src/components/VnTable/VnTable.vue index 1610735a4..c26478360 100644 --- a/src/components/VnTable/VnTable.vue +++ b/src/components/VnTable/VnTable.vue @@ -13,6 +13,7 @@ import VnLv from 'components/ui/VnLv.vue'; import VnTableColumn from 'components/VnTable/VnColumn.vue'; import VnTableFilter from 'components/VnTable/VnFilter.vue'; import VnTableChip from 'components/VnTable/VnChip.vue'; +import TableVisibleColumns from 'src/components/VnTable/VnVisibleColumn.vue'; const $props = defineProps({ columns: { @@ -67,6 +68,10 @@ const $props = defineProps({ type: Object, default: () => ({ card: false, table: false }), }, + tableCode: { + type: String, + default: null, + }, }); const { t } = useI18n(); const stateStore = useStateStore(); @@ -115,6 +120,14 @@ watch( (val) => setUserParams(val) ); +const rowClickFunction = computed(() => { + if ($props.rowClick) return $props.rowClick; + if ($props.redirect) return ({ id }) => redirectFn(id); + return () => {}; +}); + +const isTableMode = computed(() => mode.value == TABLE_MODE); + function setUserParams(watchedParams) { if (!watchedParams) return; @@ -158,12 +171,6 @@ function splitColumns(columns) { } } -const rowClickFunction = computed(() => { - if ($props.rowClick) return $props.rowClick; - if ($props.redirect) return ({ id }) => redirectFn(id); - return () => {}; -}); - function redirectFn(id) { router.push({ path: `/${$props.redirect}/${id}` }); } @@ -236,7 +243,7 @@ defineExpose({ :limit="20" ref="CrudModelRef" :search-url="searchUrl" - :disable-infinite-scroll="mode == TABLE_MODE" + :disable-infinite-scroll="isTableMode" @save-changes="reload" :has-sub-toolbar="$attrs['hasSubToolbar'] ?? isEditable" > @@ -254,11 +261,11 @@ defineExpose({ :columns="splittedColumns.columns" :rows="rows" v-model:selected="selected" - :grid="mode != TABLE_MODE" + :grid="!isTableMode" table-header-class="bg-header" card-container-class="grid-three" flat - :style="mode == TABLE_MODE && 'max-height: 90vh'" + :style="isTableMode && 'max-height: 90vh'" virtual-scroll @virtual-scroll=" (event) => @@ -272,13 +279,12 @@ defineExpose({