From 23a3b3bbe1b34e5ff0ff6bfd5ab55a57f50c6420 Mon Sep 17 00:00:00 2001 From: Donkie Date: Thu, 6 Jul 2023 15:40:07 +0200 Subject: [PATCH] Client: Vendor table is now sortable --- client/src/pages/vendors/list.tsx | 32 +++++++++++++++++++++++++----- client/src/pages/vendors/model.tsx | 2 +- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/client/src/pages/vendors/list.tsx b/client/src/pages/vendors/list.tsx index 3ec1f1c..ff7d057 100644 --- a/client/src/pages/vendors/list.tsx +++ b/client/src/pages/vendors/list.tsx @@ -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 = () => { - 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 ( - - - +
+ + ( = () => { /> )} /> - +