Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ktable): expose table data and revalidate handle #2510

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/components/KTableData/KTableData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>[]): void
(e: 'row-expand', data: any): void
}>()
Expand Down Expand Up @@ -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: _revalidate as () => Promise<void> }) // 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)!
Expand Down Expand Up @@ -513,6 +515,7 @@ const showPagination = computed((): boolean => {
watch(fetcherData, (fetchedData: Record<string, any>[]) => {
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 })

Expand Down