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

Commit

Permalink
feat(shadcn): add column scrolling to DataTable component
Browse files Browse the repository at this point in the history
  ## what
  - add column scrolling to `DataTable` component

  ## how
  - check
    - https://ui.shadcn.com/docs/components/data-table#sorting

  ## why
  - allows a column to be sorted

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

  ## usage
  • Loading branch information
Clumsy-Coder committed Jan 2, 2024
1 parent 2c7df8e commit 55f98b4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/components/ui/data-table.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"use client"

import { useState } from "react"
import {
ColumnDef,
SortingState,
flexRender,
getCoreRowModel,
getPaginationRowModel,
getSortedRowModel,
useReactTable,
} from "@tanstack/react-table"

Expand All @@ -27,11 +30,18 @@ export function DataTable<TData, TValue>({
columns,
data,
}: DataTableProps<TData, TValue>) {
const [sorting, setSorting] = useState<SortingState>([])

const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
onSortingChange: setSorting,
getSortedRowModel: getSortedRowModel(),
state: {
sorting,
},
})

return (
Expand Down

0 comments on commit 55f98b4

Please sign in to comment.