diff --git a/src/components/book-out/BookOutDataTable.tsx b/src/components/book-out/BookOutDataTable.tsx index dad193f..11cac89 100644 --- a/src/components/book-out/BookOutDataTable.tsx +++ b/src/components/book-out/BookOutDataTable.tsx @@ -6,6 +6,7 @@ import { flexRender, getCoreRowModel, useReactTable, + VisibilityState, } from "@tanstack/react-table" import { @@ -17,6 +18,13 @@ import { TableRow, } from "@/components/ui/table" import { Button } from "@/components/ui/button" +import { + DropdownMenu, + DropdownMenuCheckboxItem, + DropdownMenuContent, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu" +import { Columns } from "lucide-react" interface BookOutRecord { id: string @@ -36,65 +44,108 @@ export function BookOutDataTable({ columns, data, }: BookOutDataTableProps) { + const [columnVisibility, setColumnVisibility] = React.useState(() => { + if (typeof window !== 'undefined' && window.innerWidth < 768) { + return { + sku: false, + quantity: false, + }; + } + return {}; + }); + const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel(), + state: { + columnVisibility, + }, + onColumnVisibilityChange: setColumnVisibility, }) return ( -
- - - {table.getHeaderGroups().map((headerGroup) => ( - - {headerGroup.headers.map((header) => ( - - {header.isPlaceholder - ? null - : flexRender(header.column.columnDef.header, header.getContext())} - - ))} - - ))} - - - {table.getRowModel().rows.length ? ( - table.getRowModel().rows.map((row) => { - const record = row.original as BookOutRecord - // Calculate total quantity if quantity is array - const totalQuantity = Array.isArray(record.quantity) - ? record.quantity.reduce((sum, q) => sum + q, 0) - : record.quantity +
+
+
+ + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header) => ( + + {header.isPlaceholder + ? null + : flexRender(header.column.columnDef.header, header.getContext())} + + ))} + + ))} + + + {table.getRowModel().rows.length ? ( + table.getRowModel().rows.map((row) => { + const record = row.original as BookOutRecord + // Calculate total quantity if quantity is array + const totalQuantity = Array.isArray(record.quantity) + ? record.quantity.reduce((sum, q) => sum + q, 0) + : record.quantity - return ( - - {row.getVisibleCells().map((cell) => { - if (cell.column.id === "quantity") { + return ( + + {row.getVisibleCells().map((cell) => { + if (cell.column.id === "quantity") { + return ( + + {totalQuantity} + + ) + } return ( - - {totalQuantity} + + {flexRender(cell.column.columnDef.cell, cell.getContext())} ) - } - return ( - - {flexRender(cell.column.columnDef.cell, cell.getContext())} - - ) - })} - - ) - }) - ) : ( - - - No results. - - - )} - -
+ })} + + ) + }) + ) : ( + + + No results. + + + )} + + +
+
+ + + + + + {table + .getAllColumns() + .filter(column => column.getCanHide()) + .map(column => { + return ( + + {column.id} + + ) + })} + + +
) } \ No newline at end of file diff --git a/src/components/book-out/BookOutForm.tsx b/src/components/book-out/BookOutForm.tsx index 08663e3..16189be 100644 --- a/src/components/book-out/BookOutForm.tsx +++ b/src/components/book-out/BookOutForm.tsx @@ -219,7 +219,7 @@ export function BookOutForm({ setOpen, refreshData }: BookOutFormProps) {

Items to Book Out

{form.getValues("items").map((item, index) => ( -
+