import React from "react"; import { IResourceComponentsProps, BaseRecord, CrudSort, } from "@refinedev/core"; import { useTable, List, EditButton, ShowButton, DateField, CloneButton, } from "@refinedev/antd"; import { Table, Space } from "antd"; import dayjs from "dayjs"; import utc from "dayjs/plugin/utc"; import { genericSorter, getSortOrderForField } from "../../utils/sorting"; import { IVendor } from "./model"; dayjs.extend(utc); export const VendorList: React.FC = () => { // Load sorter state from local storage const [sorters_initial] = React.useState(() => { const storedSorters = localStorage.getItem("vendorListSorters"); if (storedSorters) { return JSON.parse(storedSorters); } return [ { field: "id", order: "asc", }, ]; }); // Fetch data from the API const { tableProps, sorters } = useTable({ 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: sorters_initial, }, }); // Store sorter state in local storage React.useEffect(() => { localStorage.setItem("vendorListSorters", JSON.stringify(sorters)); }, [sorters]); // Copy dataSource to avoid mutating the original const dataSource = [...(tableProps.dataSource || [])]; // Sort dataSource by the sorters dataSource.sort(genericSorter(sorters)); return ( ( )} /> ( )} />
); };