260917_01_fix: 컨택 목록 복귀 시 필터·정렬·페이지 상태 복원

This commit is contained in:
2026-09-17 07:35:18 +09:00
parent 38672c262d
commit c4d1a6c998
3 changed files with 23 additions and 7 deletions

View File

@@ -25,6 +25,7 @@ export function DataTable<TData, TValue = unknown>({
totalCount: serverTotalCount,
pagination: externalPagination,
onPaginationChange: onServerPaginationChange,
sorting: externalSorting,
onSortingChange: onServerSortingChange,
selectMode = 'none',
onRowClick,
@@ -41,7 +42,7 @@ export function DataTable<TData, TValue = unknown>({
bottomPinnedRows = EMPTY_PINNED_ROWS,
}: Readonly<DataTableProps<TData, TValue>>) {
const [internalPagination, setInternalPagination] = useState<PaginationState>({ pageIndex: 0, pageSize: defaultPageSize })
const [sorting, setSorting] = useState<SortingState>([])
const [internalSorting, setInternalSorting] = useState<SortingState>([])
const [rowSelection, setRowSelection] = useState<RowSelectionState>({})
const scrollContainerRef = useRef<HTMLDivElement>(null)
const drag = usePreventClickOnDrag()
@@ -78,6 +79,7 @@ export function DataTable<TData, TValue = unknown>({
}, [columns, selectMode, selectionEnabled])
const pagination = isClient ? internalPagination : (externalPagination ?? internalPagination)
const sorting = !isClient && externalSorting ? externalSorting : internalSorting
useEffect(() => {
setRowSelection({})
@@ -100,6 +102,20 @@ export function DataTable<TData, TValue = unknown>({
[isClient, onServerPaginationChange],
)
const handleSortingChange = useCallback<OnChangeFn<SortingState>>(
(updater) => {
const nextSorting = typeof updater === 'function' ? updater(sorting) : updater
if (!isClient && onServerSortingChange) {
onServerSortingChange(nextSorting)
return
}
setInternalSorting(nextSorting)
},
[isClient, onServerSortingChange, sorting],
)
const combinedData = useMemo(
() => [...topPinnedRows, ...data, ...bottomPinnedRows],
[topPinnedRows, data, bottomPinnedRows],
@@ -128,7 +144,7 @@ export function DataTable<TData, TValue = unknown>({
enableRowPinning: true,
keepPinnedRows: true,
onRowSelectionChange: setRowSelection,
onSortingChange: setSorting,
onSortingChange: handleSortingChange,
onPaginationChange: handlePaginationChange,
getCoreRowModel: getCoreRowModel(),
getSortedRowModel: isClient ? getSortedRowModel() : undefined,
@@ -139,10 +155,6 @@ export function DataTable<TData, TValue = unknown>({
getRowId: internalGetRowId,
})
useEffect(() => {
if (!isClient) onServerSortingChange?.(sorting)
}, [isClient, onServerSortingChange, sorting])
useEffect(() => {
if (!selectionEnabled) return
onRowSelectionChange?.(table.getSelectedRowModel().rows.map((row) => row.original))

View File

@@ -33,6 +33,7 @@ export interface DataTableProps<TData, TValue = unknown> {
totalCount?: number
pagination?: PaginationState
onPaginationChange?: (updater: Updater<PaginationState>) => void
sorting?: SortingState
onSortingChange?: (sorting: SortingState) => void
selectMode?: SelectMode
onRowClick?: (row: TData) => void