diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index 8ee7f8e7..a159ca5d 100644 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -59,7 +59,7 @@ export type TableProps = { // eslint-disable-next-line @typescript-eslint/no-explicit-any const defaultData: any[] = []; -const loading = <>{repeat(, 6)}; +const loading = <>{repeat(, 6)}; const Table = ({ data = defaultData, @@ -83,7 +83,7 @@ const Table = ({ : undefined; }, [sortBy]); - const { getHeaderGroups, getRowModel, getPageCount, nextPage, previousPage, setGlobalFilter, getState } = + const { getHeaderGroups, getRowModel, getPageCount, nextPage, previousPage, setGlobalFilter, getState, setSorting } = useReactTable({ columns, data, @@ -109,43 +109,53 @@ const Table = ({ return ( <> {search ? ( -
+
) : null}
{title &&
{title}
} - +
{getHeaderGroups().map((headerGroup) => ( - + {headerGroup.headers.map((header) => { const isSortable = header.column.getCanSort(); return ( rowCallback(row, index) : undefined} - className={rowCallback && 'cursor-pointer highlighted-row'} + className={rowCallback && 'highlighted-row cursor-pointer'} > {row.getVisibleCells().map((cell) => { return ( @@ -169,7 +179,7 @@ const Table = ({ key={cell.id} className={`${cell.column.columnDef.meta?.className || ''} ${ (index % 2 ? evenRowsClassname : oddRowsClassname) || 'bg-base-200' - }`} + } table-fixed`} > {flexRender(cell.column.columnDef.cell, cell.getContext())} @@ -180,7 +190,7 @@ const Table = ({
{ + if (isSortable) { + const currentSort = header.column.getIsSorted(); + setSorting([ + { + id: header.column.id, + desc: currentSort === 'asc', + }, + ]); + } + }} >
{flexRender(header.column.columnDef.header, header.getContext())} {isSortable ? ( -
+
{header.column.getIsSorted() === 'desc' ? ( - + ) : ( - + )}
) : null} @@ -161,7 +171,7 @@ const Table = ({