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 { Table, Space } from "antd";
import dayjs from "dayjs"; import dayjs from "dayjs";
import utc from "dayjs/plugin/utc"; import utc from "dayjs/plugin/utc";
import { genericSorter } from "../../utils/sorting";
dayjs.extend(utc); dayjs.extend(utc);
export const VendorList: React.FC<IResourceComponentsProps> = () => { export const VendorList: React.FC<IResourceComponentsProps> = () => {
const { tableProps } = useTable({ const { tableProps, sorters } = useTable({
syncWithLocation: true, syncWithLocation: true,
pagination: { pagination: {
mode: "client", mode: "client",
pageSize: 20, 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 ( return (
<List> <List>
<Table {...tableProps} rowKey="id"> <Table {...tableProps} dataSource={dataSource} rowKey="id">
<Table.Column dataIndex="id" title="Id" /> <Table.Column
<Table.Column dataIndex="name" title="Name" /> dataIndex="id"
title="Id"
sorter={true}
defaultSortOrder="ascend"
/>
<Table.Column dataIndex="name" title="Name" sorter={true} />
<Table.Column <Table.Column
dataIndex={["registered"]} dataIndex={["registered"]}
title="Registered" title="Registered"
sorter={true}
render={(value) => ( render={(value) => (
<DateField <DateField
value={dayjs.utc(value).local()} 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 <Table.Column
title="Actions" title="Actions"
dataIndex="actions" dataIndex="actions"

View File

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