Update pagination
- Support id pages - Set proper list max
This commit is contained in:
parent
78a30c2db4
commit
737a05e2c5
1 changed files with 19 additions and 5 deletions
|
@ -14,12 +14,20 @@ import { useContainerQuery } from '/@/renderer/hooks';
|
||||||
import { TablePagination as TablePaginationType } from '/@/renderer/types';
|
import { TablePagination as TablePaginationType } from '/@/renderer/types';
|
||||||
|
|
||||||
interface TablePaginationProps {
|
interface TablePaginationProps {
|
||||||
|
id?: string;
|
||||||
pagination: TablePaginationType;
|
pagination: TablePaginationType;
|
||||||
setPagination: (pagination: Partial<TablePaginationType>) => void;
|
setIdPagination?: (id: string, pagination: Partial<TablePaginationType>) => void;
|
||||||
|
setPagination?: (pagination: Partial<TablePaginationType>) => void;
|
||||||
tableRef: MutableRefObject<AgGridReactType | null>;
|
tableRef: MutableRefObject<AgGridReactType | null>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TablePagination = ({ tableRef, pagination, setPagination }: TablePaginationProps) => {
|
export const TablePagination = ({
|
||||||
|
id,
|
||||||
|
tableRef,
|
||||||
|
pagination,
|
||||||
|
setPagination,
|
||||||
|
setIdPagination,
|
||||||
|
}: TablePaginationProps) => {
|
||||||
const [isGoToPageOpen, handlers] = useDisclosure(false);
|
const [isGoToPageOpen, handlers] = useDisclosure(false);
|
||||||
const containerQuery = useContainerQuery();
|
const containerQuery = useContainerQuery();
|
||||||
|
|
||||||
|
@ -32,7 +40,10 @@ export const TablePagination = ({ tableRef, pagination, setPagination }: TablePa
|
||||||
const handlePagination = (index: number) => {
|
const handlePagination = (index: number) => {
|
||||||
const newPage = index - 1;
|
const newPage = index - 1;
|
||||||
tableRef.current?.api.paginationGoToPage(newPage);
|
tableRef.current?.api.paginationGoToPage(newPage);
|
||||||
setPagination({ currentPage: newPage });
|
setPagination?.({ currentPage: newPage });
|
||||||
|
setIdPagination?.(id || '', { currentPage: newPage });
|
||||||
|
|
||||||
|
console.log('newPage', newPage);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleGoSubmit = goToForm.onSubmit((values) => {
|
const handleGoSubmit = goToForm.onSubmit((values) => {
|
||||||
|
@ -43,11 +54,14 @@ export const TablePagination = ({ tableRef, pagination, setPagination }: TablePa
|
||||||
|
|
||||||
const newPage = values.pageNumber - 1;
|
const newPage = values.pageNumber - 1;
|
||||||
tableRef.current?.api.paginationGoToPage(newPage);
|
tableRef.current?.api.paginationGoToPage(newPage);
|
||||||
setPagination({ currentPage: newPage });
|
setPagination?.({ currentPage: newPage });
|
||||||
|
setIdPagination?.(id || '', { currentPage: newPage });
|
||||||
});
|
});
|
||||||
|
|
||||||
const currentPageStartIndex = pagination.currentPage * pagination.itemsPerPage + 1;
|
const currentPageStartIndex = pagination.currentPage * pagination.itemsPerPage + 1;
|
||||||
const currentPageStopIndex = (pagination.currentPage + 1) * pagination.itemsPerPage;
|
const currentPageMaxIndex = (pagination.currentPage + 1) * pagination.itemsPerPage;
|
||||||
|
const currentPageStopIndex =
|
||||||
|
currentPageMaxIndex > pagination.totalItems ? pagination.totalItems : currentPageMaxIndex;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MotionFlex
|
<MotionFlex
|
||||||
|
|
Reference in a new issue