Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
feat(shadcn:data-table): set DataTable height if provided
Browse files Browse the repository at this point in the history
  ## what
  - set DataTable height if provided

  ## how
  - take `height` as a prop
  - set the height of the table if it's defined
  - set the table to overflow-y if height is defined

  ## why
  - a replacement for `VirtualTable`
    - VirtualTable struggles to scroll when theres high amounts of items
      to render. DataTable can handle high items without issue
  - to have the ability to set the size of the DataTable

  ## where
  - ./src/components/ui/data-table/index.tsx

  ## usage
  • Loading branch information
Clumsy-Coder committed Jan 12, 2024
1 parent 94a5b39 commit c58b14f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/ui/data-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ import { DataTablePagination } from "@/components/ui/data-table/pagination"
interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[]
data: TData[]
/**
* height of the table. If specified, it will overflow the table contents
*/
height?: number
}

export function DataTable<TData, TValue>({
columns,
data,
height
}: DataTableProps<TData, TValue>) {
const [sorting, setSorting] = useState<SortingState>([])
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
Expand Down Expand Up @@ -128,7 +133,7 @@ export function DataTable<TData, TValue>({
</DropdownMenuContent>
</DropdownMenu>
</div>
<div className="rounded-md border">
<div className={`rounded-md border ${height ? `h-[${height}px] overflow-y-auto` : null}`}>
<Table>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
Expand Down

0 comments on commit c58b14f

Please sign in to comment.