Skip to content

Commit

Permalink
fix(ktableview, ktabledata): table updates event [KHCP-14032] (#2520)
Browse files Browse the repository at this point in the history
  • Loading branch information
portikM authored Nov 18, 2024
1 parent b24c68e commit ce27dca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/components/KTableData/KTableData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@row-expand="($event: Record<string, any>) => emit('row-expand', $event)"
@row-select="($event: Record<string, any>[]) => emit('row-select', $event)"
@sort="sortHandler"
@update:table-preferences="tableViewPreferences = $event"
@update:table-preferences="tablePreferencesUpdateHandler"
>
<template
v-if="$slots.toolbar && !hideToolbar"
Expand Down Expand Up @@ -258,11 +258,11 @@ const hasInitialized = ref<boolean>(false)
const defaultFetcherProps = {
pageSize: pageSize.value,
page: 1,
query: '',
sortColumnKey: '',
sortColumnOrder: 'desc',
offset: null,
page: page.value,
query: filterQuery.value,
sortColumnKey: sortColumnKey.value,
sortColumnOrder: sortColumnOrder.value,
offset: offset.value,
}
const tablePaginationAttributes = computed((): TablePaginationAttributes => ({
Expand Down Expand Up @@ -450,9 +450,6 @@ const sortHandler = ({ sortColumnKey: columnKey, prevKey, sortColumnOrder: sortO
} else if (!props.paginationAttributes?.offset) {
debouncedRevalidate()
}
// Emit an event whenever one of the tablePreferences are updated
emitTablePreferences()
}
const pageChangeHandler = ({ page: newPage }: PageChangeData) => {
Expand All @@ -464,13 +461,25 @@ const pageSizeChangeHandler = ({ pageSize: newPageSize }: PageSizeChangeData) =>
offset.value = null
pageSize.value = newPageSize
page.value = 1
}
const tablePreferencesUpdateHandler = ({ columnWidths: newColumnWidth, columnVisibility: newColumnVisibility }: TablePreferences) => {
tableViewColumnWidths.value = newColumnWidth
tableViewColumnVisibility.value = newColumnVisibility
// Emit an event whenever one of the tablePreferences are updated
emitTablePreferences()
}
const tableViewPreferences = ref<TablePreferences>({})
const tableDataPreferences = computed((): TablePreferences => ({ pageSize: pageSize.value, ...tableViewPreferences.value }))
const tableViewColumnWidths = ref<Record<string, number> | undefined>({})
const tableViewColumnVisibility = ref<Record<string, boolean> | undefined>({})
const tableDataPreferences = computed((): TablePreferences => ({
pageSize: pageSize.value,
sortColumnKey: sortColumnKey.value,
sortColumnOrder: sortColumnOrder.value,
...(tableViewColumnWidths.value ? { columnWidths: tableViewColumnWidths.value } : {}),
...(tableViewColumnVisibility.value ? { columnVisibility: tableViewColumnVisibility.value } : {}),
}))
const emitTablePreferences = (): void => {
if (tableState.value === 'success') {
Expand Down Expand Up @@ -580,10 +589,6 @@ watch([query, page, pageSize], async (newData, oldData) => {
}
}, { deep: true, immediate: true })
watch(tableDataPreferences, () => {
emitTablePreferences()
}, { immediate: true })
onMounted(() => {
initData()
})
Expand Down
4 changes: 4 additions & 0 deletions src/components/KTableView/KTableView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ const startResize = (evt: MouseEvent, colKey: string) => {
document?.removeEventListener('mousemove', mouseMoveHandler)
document?.removeEventListener('mouseup', mouseUpHandler)
emitTablePreferences()
if (hasExpandableRows.value) {
setActualColumnWidths()
}
Expand Down Expand Up @@ -954,6 +955,9 @@ const paginationPageSize = ref<number>(getInitialPageSize(props.tablePreferences
const onPaginationPageSizeChange = (data: PageSizeChangeData): void => {
paginationPageSize.value = data.pageSize
emit('page-size-change', data)
// Emit an event whenever one of the tablePreferences are updated
emitTablePreferences()
}
// Store the tablePreferences in a computed property to utilize in the watcher
Expand Down

0 comments on commit ce27dca

Please sign in to comment.