Client: Vendor table is now sortable

This commit is contained in:
Donkie
2023-07-06 15:40:07 +02:00
parent d0f67d766c
commit 23a3b3bbe1
2 changed files with 28 additions and 6 deletions

View File

@@ -11,26 +11,48 @@ import {
import { Table, Space } from "antd";
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import { genericSorter } from "../../utils/sorting";
dayjs.extend(utc);
export const VendorList: React.FC<IResourceComponentsProps> = () => {
const { tableProps } = useTable({
const { tableProps, sorters } = useTable({
syncWithLocation: true,
pagination: {
mode: "client",
pageSize: 20,
},
sorters: {
mode: "off", // Disable server-side sorting
initial: [
{
field: "id",
order: "asc",
},
],
},
});
// Copy dataSource to avoid mutating the original
const dataSource = [...(tableProps.dataSource || [])];
// Sort dataSource by the sorters
dataSource.sort(genericSorter(sorters));
return (
<List>
<Table {...tableProps} rowKey="id">
<Table.Column dataIndex="id" title="Id" />
<Table.Column dataIndex="name" title="Name" />
<Table {...tableProps} dataSource={dataSource} rowKey="id">
<Table.Column
dataIndex="id"
title="Id"
sorter={true}
defaultSortOrder="ascend"
/>
<Table.Column dataIndex="name" title="Name" sorter={true} />
<Table.Column
dataIndex={["registered"]}
title="Registered"
sorter={true}
render={(value) => (
<DateField
value={dayjs.utc(value).local()}
@@ -39,7 +61,7 @@ export const VendorList: React.FC<IResourceComponentsProps> = () => {
/>
)}
/>
<Table.Column dataIndex={["comment"]} title="Comment" />
<Table.Column dataIndex={["comment"]} title="Comment" sorter={true} />
<Table.Column
title="Actions"
dataIndex="actions"

View File

@@ -1,5 +1,5 @@
export interface IVendor {
id: string;
id: number;
registered: string;
name: string;
comment?: string;