feat(tables): implement sortable columns across various table components
- Added TableSortProvider to manage sorting state in AdminsTable, CmsTable, CompaniesTable, CustomersTable, TendersTable, and CompanyCategoriesTable. - Enhanced TableHead component to support sortable columns with visual indicators for sort direction. - Introduced columnSortKeys and columnDefaultOrder mappings in respective table presenters to define sortable fields and default sorting behavior. - Updated useCompanyListPresenter, useCmsTablePresenter, useCustomerListPresenter, useTenderListPresenter, and useCompanyCategoriesPresenter to handle sorting logic and state management. - Improved user experience by allowing dynamic sorting of table data based on user interactions.
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
TableSortProvider,
|
||||
} from "@/components/ui/table";
|
||||
import IsVisible from "@/components/ui/IsVisible";
|
||||
import ListHeader from "@/components/ui/ListHeader";
|
||||
@@ -25,6 +26,11 @@ import useTenderListPresenter from "./useTenderListPresenter";
|
||||
const TendersTable = () => {
|
||||
const {
|
||||
columns,
|
||||
columnSortKeys,
|
||||
columnDefaultOrder,
|
||||
sortBy,
|
||||
sortOrder,
|
||||
handleSortChange,
|
||||
filterRegister,
|
||||
handleFilterSubmit,
|
||||
search,
|
||||
@@ -67,14 +73,28 @@ const TendersTable = () => {
|
||||
onClearAll={clearAllFilters}
|
||||
/>
|
||||
<div ref={tableSectionRef}>
|
||||
<TableSortProvider
|
||||
sortKey={sortBy}
|
||||
sortOrder={sortOrder}
|
||||
onSortChange={handleSortChange}
|
||||
>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow className="border-none uppercase [&>th]:text-start">
|
||||
{columns.map((column) => (
|
||||
<TableHead key={column} colSpan={100}>
|
||||
{column}
|
||||
</TableHead>
|
||||
))}
|
||||
{columns.map((column) => {
|
||||
const sortKey = columnSortKeys[column];
|
||||
return (
|
||||
<TableHead
|
||||
key={column}
|
||||
colSpan={100}
|
||||
sortable={Boolean(sortKey)}
|
||||
sortKey={sortKey}
|
||||
defaultSortOrder={columnDefaultOrder[column]}
|
||||
>
|
||||
{column}
|
||||
</TableHead>
|
||||
);
|
||||
})}
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
|
||||
@@ -153,6 +173,7 @@ const TendersTable = () => {
|
||||
</TableBody>
|
||||
)}
|
||||
</Table>
|
||||
</TableSortProvider>
|
||||
</div>
|
||||
<IsVisible condition={shouldShowPagination}>
|
||||
<Pagination
|
||||
|
||||
Reference in New Issue
Block a user