diff --git a/src/components/data-table/Footer/index.tsx b/src/components/data-table/Footer/index.tsx index 772214d..c79bd70 100644 --- a/src/components/data-table/Footer/index.tsx +++ b/src/components/data-table/Footer/index.tsx @@ -1,7 +1,12 @@ 'use client'; import { Table } from '@tanstack/react-table'; -import { ChevronLeft, ChevronRight } from 'lucide-react'; +import { + ChevronLeft, + ChevronRight, + ChevronsLeft, + ChevronsRight, +} from 'lucide-react'; import { Button } from '@/components/ui/button'; import { @@ -25,26 +30,33 @@ export function TableFooter({ pageSize?: number; onPageSizeChange?: (pageSize: number) => void; }) { - const rows = table.getRowModel().rows.length; const currentPageSize = pageSize ?? table.getState().pagination.pageSize; + const selectedRowCount = Object.keys(table.getState().rowSelection).length; + const pageIndex = table.getState().pagination.pageIndex; + const rawPageCount = table.getPageCount(); + const pageCount = Math.max( + 1, + Number.isFinite(rawPageCount) && rawPageCount > 0 ? rawPageCount : 1, + ); return ( -
-
- - Showing {rows} of {totalItems} - +
+
+ {selectedRowCount} of {totalItems} row(s) selected. +
+ +
{onPageSizeChange ? ( -
- Rows per page +
+ Rows per page
) : null} -
-
- - + +
+ Page {pageIndex + 1} of {pageCount} +
+ +
+ + + + +
); diff --git a/src/components/data-table/Header/index.tsx b/src/components/data-table/Header/index.tsx index 7fd8b67..71f6a43 100644 --- a/src/components/data-table/Header/index.tsx +++ b/src/components/data-table/Header/index.tsx @@ -21,26 +21,35 @@ const TopHeader = ({ tableTools, }: TopHeaderProps) => { return ( -
+
{(title || onAddNew) && ( -
-
- {title ?

{title}

: null} -

Total {itemCount ?? 0}

+
+
+ {title ?

{title}

: null} +

+ Total {itemCount ?? 0} +

{onAddNew ? ( - ) : null}
)} + {(toolbar || tableTools) && (
-
{toolbar}
+ {toolbar ? ( +
+ {toolbar} +
+ ) : null} {tableTools ? ( -
{tableTools}
+
+ {tableTools} +
) : null}
)} diff --git a/src/components/data-table/TableHeader.tsx b/src/components/data-table/TableHeader.tsx index 568c1e0..d41d1a3 100644 --- a/src/components/data-table/TableHeader.tsx +++ b/src/components/data-table/TableHeader.tsx @@ -16,7 +16,7 @@ import { getPinnedColumnStyles } from './columnStyles'; const TableHeader = ({ table }: { table: Table }) => { return ( - + {table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => { @@ -39,9 +39,9 @@ const TableHeader = ({ table }: { table: Table }) => { canSort ? header.column.getToggleSortingHandler() : undefined } className={cn( - 'h-10 max-w-0 overflow-hidden border-b border-border bg-card px-2 text-foreground transition-colors', - canSort && 'cursor-pointer select-none hover:bg-muted/60', - sortDirection && 'bg-muted/70', + 'h-11 max-w-0 overflow-hidden border-b border-border bg-muted/70 px-4 text-sm font-semibold text-foreground transition-colors', + canSort && 'cursor-pointer select-none hover:bg-muted', + sortDirection && 'bg-muted', )} > {header.isPlaceholder ? null : ( diff --git a/src/components/data-table/TableSearchInput.tsx b/src/components/data-table/TableSearchInput.tsx index 18503d0..7e3f080 100644 --- a/src/components/data-table/TableSearchInput.tsx +++ b/src/components/data-table/TableSearchInput.tsx @@ -23,14 +23,20 @@ export function TableSearchInput({ className, }: TableSearchInputProps) { return ( - + - + onChange(event.target.value)} placeholder={placeholder} + className="placeholder:text-muted-foreground/70" /> ); diff --git a/src/components/data-table/index.tsx b/src/components/data-table/index.tsx index d668d35..7685d90 100644 --- a/src/components/data-table/index.tsx +++ b/src/components/data-table/index.tsx @@ -210,8 +210,8 @@ function DataTableContent({ }, manualPagination: !!pagination, manualSorting: isManualSorting, - pageCount: pagination?.totalItems - ? Math.ceil(pagination.totalItems / pagination.limit) + pageCount: pagination + ? Math.ceil((pagination.totalItems ?? data.length) / pagination.limit) : -1, state: { rowSelection, @@ -247,7 +247,7 @@ function DataTableContent({ return ( <> -
+
({ } /> -
+
@@ -273,7 +273,7 @@ function DataTableContent({ {columns.map((_, colIdx) => ( @@ -290,7 +290,9 @@ function DataTableContent({ const truncate = shouldTruncateCell(cell.column); const pinned = cell.column.getIsPinned(); const isActionsCell = cell.column.id === 'actions'; - const isRowClickable = Boolean(onRowClick && !isActionsCell); + const isRowClickable = Boolean( + onRowClick && !isActionsCell, + ); const content = flexRender( cell.column.columnDef.cell, cell.getContext(), @@ -306,8 +308,8 @@ function DataTableContent({ : undefined } className={cn( - 'max-w-0 overflow-hidden border-b border-border', - pinned && 'bg-card', + 'h-13 max-w-0 overflow-hidden border-b border-border px-4 py-3 text-sm', + pinned && 'bg-background', isRowClickable && 'cursor-pointer', isActionsCell && 'cursor-default', )}