Enhance DataTable component pagination and sorting UI (#152)
- Adjust pagination layout and styling for better readability - Add support for optional sorting change event handler - Improve sorting state management with flexible updater function - Update text color and spacing in pagination component
This commit is contained in:
committed by
GitHub
parent
97e4bc9bad
commit
e2f45cae49
@@ -46,6 +46,7 @@ interface ReactTableProps<T extends object> {
|
|||||||
pageSize?: number;
|
pageSize?: number;
|
||||||
pageCount?: number;
|
pageCount?: number;
|
||||||
onPaginationChange?: (pagination: PaginationState) => void;
|
onPaginationChange?: (pagination: PaginationState) => void;
|
||||||
|
onSortingChange?: (sorting: SortingState) => void;
|
||||||
manualPagination?: boolean;
|
manualPagination?: boolean;
|
||||||
manualSorting?: boolean;
|
manualSorting?: boolean;
|
||||||
sorting?: SortingState;
|
sorting?: SortingState;
|
||||||
@@ -60,6 +61,7 @@ export function DataTable<T extends object>({
|
|||||||
pageSize,
|
pageSize,
|
||||||
pageCount,
|
pageCount,
|
||||||
onPaginationChange,
|
onPaginationChange,
|
||||||
|
onSortingChange,
|
||||||
tableProps,
|
tableProps,
|
||||||
manualPagination = true,
|
manualPagination = true,
|
||||||
manualSorting = false,
|
manualSorting = false,
|
||||||
@@ -84,7 +86,6 @@ export function DataTable<T extends object>({
|
|||||||
getSortedRowModel: getSortedRowModel(),
|
getSortedRowModel: getSortedRowModel(),
|
||||||
manualPagination,
|
manualPagination,
|
||||||
manualSorting,
|
manualSorting,
|
||||||
onSortingChange: setSorting,
|
|
||||||
onColumnFiltersChange: setColumnFilters,
|
onColumnFiltersChange: setColumnFilters,
|
||||||
onColumnVisibilityChange: setColumnVisibility,
|
onColumnVisibilityChange: setColumnVisibility,
|
||||||
onRowSelectionChange: setRowSelection,
|
onRowSelectionChange: setRowSelection,
|
||||||
@@ -96,6 +97,23 @@ export function DataTable<T extends object>({
|
|||||||
columnVisibility,
|
columnVisibility,
|
||||||
rowSelection,
|
rowSelection,
|
||||||
},
|
},
|
||||||
|
onSortingChange: (updater) => {
|
||||||
|
if (typeof updater === 'function') {
|
||||||
|
const nextState = updater(sorting);
|
||||||
|
|
||||||
|
setSorting(nextState);
|
||||||
|
|
||||||
|
if (onSortingChange) {
|
||||||
|
onSortingChange(nextState);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setSorting(updater);
|
||||||
|
|
||||||
|
if (onSortingChange) {
|
||||||
|
onSortingChange(updater);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
onPaginationChange: (updater) => {
|
onPaginationChange: (updater) => {
|
||||||
const navigate = (page: number) => setTimeout(() => navigateToPage(page));
|
const navigate = (page: number) => setTimeout(() => navigateToPage(page));
|
||||||
|
|
||||||
@@ -190,8 +208,8 @@ function Pagination<T>({
|
|||||||
table: ReactTable<T>;
|
table: ReactTable<T>;
|
||||||
}>) {
|
}>) {
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center justify-end gap-x-4">
|
<div className="flex items-center gap-x-4">
|
||||||
<span className="flex items-center text-sm">
|
<span className="text-muted-foreground flex items-center text-sm">
|
||||||
<Trans
|
<Trans
|
||||||
i18nKey={'common:pageOfPages'}
|
i18nKey={'common:pageOfPages'}
|
||||||
values={{
|
values={{
|
||||||
@@ -201,7 +219,7 @@ function Pagination<T>({
|
|||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<div className="flex items-center justify-end gap-x-2">
|
<div className="flex items-center gap-x-1">
|
||||||
<Button
|
<Button
|
||||||
size={'icon'}
|
size={'icon'}
|
||||||
variant={'ghost'}
|
variant={'ghost'}
|
||||||
|
|||||||
Reference in New Issue
Block a user