fix(ui): сохранять страницу компактной таблицы при опросе
This commit is contained in:
1 parent
160b39186a
commit
ef457b471a
6 files changed
+33
-6
No files matched your search
@@ -2,7 +2,7 @@
|
||||
|
||||
import { dataGridFeatures, type DataGridFeatures } from "@/components/reui/data-grid"
|
||||
|
||||
import { useMemo, type ReactNode } from "react"
|
||||
import { useMemo, useEffect, type ReactNode } from "react"
|
||||
import {
|
||||
type ColumnDef,
|
||||
useTable,
|
||||
@@ -83,6 +83,7 @@ function CompactDataGrid<T extends { id: string }>({
|
||||
const table = useTable({
|
||||
features: dataGridFeatures,
|
||||
manualPagination: false,
|
||||
autoResetPageIndex: false,
|
||||
initialState: { pagination: { pageIndex: 0, pageSize: 50 } },
|
||||
data,
|
||||
columns: columnDefs,
|
||||
@@ -90,6 +91,12 @@ function CompactDataGrid<T extends { id: string }>({
|
||||
...(getExpandedContent ? { getRowCanExpand: () => true } : {}),
|
||||
})
|
||||
|
||||
const {pageIndex,pageSize}=table.state.pagination
|
||||
useEffect(()=>{
|
||||
const last=Math.max(0,Math.ceil(data.length/pageSize)-1)
|
||||
if(pageIndex>last)table.setPageIndex(last)
|
||||
},[data.length,pageSize,pageIndex,table])
|
||||
|
||||
return (
|
||||
<DataGridShell
|
||||
table={table}
|
||||
|
||||
Reference in new issue
Block a user