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) { - - - + + + + + + + + + + -