Client: Fixed up pagination, now also stored
This commit is contained in:
58
client/src/pages/vendors/list.tsx
vendored
58
client/src/pages/vendors/list.tsx
vendored
@@ -31,28 +31,43 @@ export const VendorList: React.FC<IResourceComponentsProps> = () => {
|
||||
const initialState = useInitialTableState("vendorList");
|
||||
|
||||
// Fetch data from the API
|
||||
const { tableProps, sorters, filters, setSorters, setFilters } =
|
||||
useTable<IVendor>({
|
||||
syncWithLocation: false,
|
||||
pagination: {
|
||||
mode: "off", // Perform pagination in antd's Table instead. Otherwise client-side sorting/filtering doesn't work.
|
||||
},
|
||||
sorters: {
|
||||
mode: "off", // Disable server-side sorting
|
||||
initial: initialState.sorters,
|
||||
},
|
||||
filters: {
|
||||
mode: "off", // Disable server-side filtering
|
||||
initial: initialState.filters,
|
||||
},
|
||||
});
|
||||
const {
|
||||
tableProps,
|
||||
sorters,
|
||||
setSorters,
|
||||
filters,
|
||||
setFilters,
|
||||
current,
|
||||
pageSize,
|
||||
setCurrent,
|
||||
setPageSize,
|
||||
} = useTable<IVendor>({
|
||||
syncWithLocation: false,
|
||||
pagination: {
|
||||
mode: "off", // Perform pagination in antd's Table instead. Otherwise client-side sorting/filtering doesn't work.
|
||||
current: initialState.pagination.current,
|
||||
pageSize: initialState.pagination.pageSize,
|
||||
},
|
||||
sorters: {
|
||||
mode: "off", // Disable server-side sorting
|
||||
initial: initialState.sorters,
|
||||
},
|
||||
filters: {
|
||||
mode: "off", // Disable server-side filtering
|
||||
initial: initialState.filters,
|
||||
},
|
||||
});
|
||||
|
||||
// Type the sorters and filters
|
||||
const typedSorters = typeSorters<IVendor>(sorters);
|
||||
const typedFilters = typeFilters<IVendor>(filters);
|
||||
|
||||
// Store state in local storage
|
||||
useStoreInitialState("vendorList", { sorters, filters });
|
||||
useStoreInitialState("vendorList", {
|
||||
sorters,
|
||||
filters,
|
||||
pagination: { current, pageSize },
|
||||
});
|
||||
|
||||
// Collapse the dataSource to a mutable list
|
||||
const dataSource: IVendor[] = React.useMemo(
|
||||
@@ -77,6 +92,7 @@ export const VendorList: React.FC<IResourceComponentsProps> = () => {
|
||||
onClick={() => {
|
||||
setFilters([], "replace");
|
||||
setSorters([{ field: "id", order: "asc" }]);
|
||||
setCurrent(1);
|
||||
}}
|
||||
>
|
||||
Clear Filters
|
||||
@@ -88,7 +104,15 @@ export const VendorList: React.FC<IResourceComponentsProps> = () => {
|
||||
<Table
|
||||
{...tableProps}
|
||||
dataSource={filteredDataSource}
|
||||
pagination={{ showSizeChanger: true, pageSize: 20 }}
|
||||
pagination={{
|
||||
showSizeChanger: true,
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
onChange: (page, pageSize) => {
|
||||
setCurrent(page);
|
||||
setPageSize(pageSize);
|
||||
},
|
||||
}}
|
||||
rowKey="id"
|
||||
>
|
||||
<Table.Column
|
||||
|
||||
Reference in New Issue
Block a user