From dcfadcf4a0d9b6a43e63063751d63c1815e2cdc7 Mon Sep 17 00:00:00 2001 From: Abizrh Date: Sat, 27 Sep 2025 23:14:56 +0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat=20(pub):=20adjust=20data=20tab?= =?UTF-8?q?le?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pub/base/data-table/data-table.vue | 64 ++++++++++++++----- 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/app/components/pub/base/data-table/data-table.vue b/app/components/pub/base/data-table/data-table.vue index ccb41100..8c9cbf50 100644 --- a/app/components/pub/base/data-table/data-table.vue +++ b/app/components/pub/base/data-table/data-table.vue @@ -13,6 +13,12 @@ const props = defineProps<{ funcParsed: RecStrFuncUnknown funcHtml: RecStrFuncUnknown funcComponent: RecStrFuncComponent + selectMode?: 'single' | 'multiple' + modelValue?: any[] | any +}>() + +const emit = defineEmits<{ + (e: 'update:modelValue', val: any[] | any): void }>() const getSkeletonSize = computed(() => { @@ -20,6 +26,24 @@ const getSkeletonSize = computed(() => { }) const loader = inject('table_data_loader') as DataTableLoader +// local state utk selection +const selected = ref([]) + +function toggleSelection(row: any) { + if (props.selectMode === 'single') { + selected.value = [row] + emit('update:modelValue', row) + } else { + const idx = selected.value.findIndex((r) => r === row) + if (idx >= 0) { + selected.value.splice(idx, 1) + } else { + selected.value.push(row) + } + emit('update:modelValue', [...selected.value]) + } +} + function handleActionCellClick(event: Event, _cellRef: string) { // Prevent event if clicked directly on the button/dropdown const target = event.target as HTMLElement @@ -70,32 +94,38 @@ function handleActionCellClick(event: Event, _cellRef: string) { - - - + + + + + + + + + + -