diff --git a/client/src/pages/spools/list.tsx b/client/src/pages/spools/list.tsx index 01919d0..81fd665 100644 --- a/client/src/pages/spools/list.tsx +++ b/client/src/pages/spools/list.tsx @@ -13,19 +13,36 @@ import { Table, Space } from "antd"; import { NumberFieldUnit } from "../../components/numberField"; import dayjs from "dayjs"; import utc from "dayjs/plugin/utc"; +import { genericSorter } from "../../utils/sorting"; dayjs.extend(utc); export const SpoolList: 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", + }, + ], + }, }); - tableProps.dataSource?.forEach((element) => { + // Copy dataSource to avoid mutating the original + const dataSource = [...(tableProps.dataSource || [])]; + + // Sort dataSource by the sorters + dataSource.sort(genericSorter(sorters)); + + // Add a filament_name field to the dataSource + dataSource.forEach((element) => { if ("vendor" in element.filament) { element.filament_name = `${element.filament.vendor.name} - ${element.filament.name}`; } else { @@ -35,12 +52,22 @@ export const SpoolList: React.FC = () => { return ( - - - +
+ + { return ( = () => { { if (value === null || value === undefined) { return ; @@ -71,11 +99,12 @@ export const SpoolList: React.FC = () => { ); }} /> - - + + (