From bf410c2b93505edde069610597187ece17265495 Mon Sep 17 00:00:00 2001 From: Tian Tan Date: Tue, 12 Nov 2024 13:46:45 +0800 Subject: [PATCH 1/3] feat(ktable): expose table data and revalidate handle --- src/components/KTableData/KTableData.vue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/KTableData/KTableData.vue b/src/components/KTableData/KTableData.vue index 961785dc87..261b4a36be 100644 --- a/src/components/KTableData/KTableData.vue +++ b/src/components/KTableData/KTableData.vue @@ -229,6 +229,7 @@ const emit = defineEmits<{ (e: 'update:table-preferences', preferences: TablePreferences): void (e: 'sort', value: TableSortPayload): void (e: 'state', value: TableStatePayload): void + (e: 'data', data: any): void (e: 'row-select', data: Record[]): void (e: 'row-expand', data: any): void }>() @@ -416,6 +417,7 @@ const stateData = computed((): SwrvStateData => ({ const tableState = computed((): TableState => isTableLoading.value ? 'loading' : fetcherError.value ? 'error' : 'success') const { debouncedFn: debouncedRevalidate, generateDebouncedFn: generateDebouncedRevalidate } = useDebounce(_revalidate, 500) const revalidate = generateDebouncedRevalidate(0) // generate a debounced function with zero delay (immediate) +defineExpose({ revalidate }) // expose revalidate function to parent component const sortHandler = ({ sortColumnKey: columnKey, prevKey, sortColumnOrder: sortOrder }: TableSortPayload): void => { const header: TableDataHeader = tableHeaders.value.find((header) => header.key === columnKey)! @@ -513,6 +515,7 @@ const showPagination = computed((): boolean => { watch(fetcherData, (fetchedData: Record[]) => { if (fetchedData?.length && !tableData.value.length) { tableData.value = fetchedData + emit('data', fetchedData) // emit data to father component when data is fetched } }, { deep: true, immediate: true }) From 00665a2cc8e5e4db3651788ba4fb7b09e83e9659 Mon Sep 17 00:00:00 2001 From: Tian Tan Date: Tue, 12 Nov 2024 14:40:37 +0800 Subject: [PATCH 2/3] chore(ktabledata): build --- src/components/KTableData/KTableData.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/KTableData/KTableData.vue b/src/components/KTableData/KTableData.vue index 261b4a36be..e1cc2db44e 100644 --- a/src/components/KTableData/KTableData.vue +++ b/src/components/KTableData/KTableData.vue @@ -417,7 +417,7 @@ const stateData = computed((): SwrvStateData => ({ const tableState = computed((): TableState => isTableLoading.value ? 'loading' : fetcherError.value ? 'error' : 'success') const { debouncedFn: debouncedRevalidate, generateDebouncedFn: generateDebouncedRevalidate } = useDebounce(_revalidate, 500) const revalidate = generateDebouncedRevalidate(0) // generate a debounced function with zero delay (immediate) -defineExpose({ revalidate }) // expose revalidate function to parent component +// defineExpose({ revalidate }) // expose revalidate function to parent component const sortHandler = ({ sortColumnKey: columnKey, prevKey, sortColumnOrder: sortOrder }: TableSortPayload): void => { const header: TableDataHeader = tableHeaders.value.find((header) => header.key === columnKey)! From 9016cf3b1dff0cda006d15e2b4f0d8e29b1b0291 Mon Sep 17 00:00:00 2001 From: Tian Tan Date: Tue, 12 Nov 2024 14:50:38 +0800 Subject: [PATCH 3/3] chore(ktabledata): fix type resolve issue --- src/components/KTableData/KTableData.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/KTableData/KTableData.vue b/src/components/KTableData/KTableData.vue index e1cc2db44e..6cfb2f8233 100644 --- a/src/components/KTableData/KTableData.vue +++ b/src/components/KTableData/KTableData.vue @@ -417,7 +417,7 @@ const stateData = computed((): SwrvStateData => ({ const tableState = computed((): TableState => isTableLoading.value ? 'loading' : fetcherError.value ? 'error' : 'success') const { debouncedFn: debouncedRevalidate, generateDebouncedFn: generateDebouncedRevalidate } = useDebounce(_revalidate, 500) const revalidate = generateDebouncedRevalidate(0) // generate a debounced function with zero delay (immediate) -// defineExpose({ revalidate }) // expose revalidate function to parent component +defineExpose({ revalidate: _revalidate as () => Promise }) // expose revalidate function to parent component const sortHandler = ({ sortColumnKey: columnKey, prevKey, sortColumnOrder: sortOrder }: TableSortPayload): void => { const header: TableDataHeader = tableHeaders.value.find((header) => header.key === columnKey)!