Data Table
A simplified wrapper for Shadcn Data Table with flexible item handling and automatic type conversion
| Status | ||||||||
|---|---|---|---|---|---|---|---|---|
EMP-1000 | John Doe | john.doe@company.com | Engineering | Manager | Active | $94,716.00 | 2022-02-05 | New York |
EMP-1001 | Jane Smith | jane.smith@company.com | Marketing | Senior | Inactive | $123,514.00 | 2021-01-15 | San Francisco |
EMP-1002 | Mike Johnson | mike.johnson@company.com | Sales | Junior | Pending | $108,267.00 | 2024-08-03 | London |
EMP-1003 | Sarah Williams | sarah.williams@company.com | HR | Lead | On Leave | $103,649.00 | 2020-10-24 | Tokyo |
EMP-1004 | David Brown | david.brown@company.com | Finance | Intern | Active | $92,400.00 | 2022-02-26 | Berlin |
EMP-1005 | Emily Davis | emily.davis@company.com | Engineering | Manager | Inactive | $76,559.00 | 2022-04-03 | New York |
EMP-1006 | Michael Wilson | michael.wilson@company.com | Marketing | Senior | Pending | $85,616.00 | 2023-05-21 | San Francisco |
EMP-1007 | Jessica Moore | jessica.moore@company.com | Sales | Junior | On Leave | $118,918.00 | 2021-01-16 | London |
EMP-1008 | Christopher Taylor | christopher.taylor@company.com | HR | Lead | Active | $125,186.00 | 2023-11-02 | Tokyo |
EMP-1009 | Amanda Anderson | amanda.anderson@company.com | Finance | Intern | Inactive | $147,736.00 | 2024-06-20 | Berlin |
Rows per page
Installation
npx shadcn@latest add @glrk-ui/data-tableData table with virtualization.
npx shadcn@latest add @glrk-ui/data-table @glrk-ui/data-table-virtualIf you haven't set up the prerequisites yet, check out registry setup.
Usage
DataTable
import { useTable } from "@tanstack/react-table";
import { DataTable, appTableFeatures } from '@/components/ui/data-table';
function MyTable() {
const table = useTable({ features: appTableFeatures, data, columns })
return <DataTable table={table} />
}DataTableVirtualized
import { useTable } from "@tanstack/react-table";
import { DataTableVirtualized, appTableFeatures } from '@/components/ui/data-table';
function MyTable() {
const {
data,
fetchNextPage,
hasNextPage,
isFetchingNextPage,
} = useInfiniteQuery()
const table = useTable({
features: appTableFeatures,
data: data.pages.flat(),
columns,
})
return (
<DataTableVirtualized
table={table}
hasNextPage={hasNextPage}
isFetchingNextPage={isFetchingNextPage}
fetchNextPage={fetchNextPage}
className="h-[600px]" // Fixed height required
/>
)
}useDataTable Hook
Custom hook (TanStack Table v9) for managing table state and configuration. Registers the sorted, filtered, paginated and faceted row models through appTableFeatures. Pre-configured with columnVisibility, columnFilters (Faceted), sorting, rowSelection, globalFilter, pagination.
So you can use most of the functionality of tanstack-table just using this hook.
import { useDataTable, DataTable } from '@/components/ui/data-table';
function MyTable() {
const table = useDataTable({ data, columns })
return (
<>
//... Other components
<DataTable table={table} />
</>
)
}ColumnSorter
Simple column header with sorting functionality.
const columns: AppColumnDef<User>[] = [
{
accessorKey: 'name',
header: ({ column }) => (
<ColumnSorter column={column} title="Name" />
),
},
]ColumnHeader
Advanced column header with dropdown menu for sorting and visibility.
const columns: AppColumnDef<User>[] = [
{
accessorKey: 'name',
header: ({ column }) => (
<ColumnHeader column={column} title="Name" />
),
},
]ColumnFilter
Multi-select dropdown filter for column values.
<ColumnFilter
title="Role"
column={table.getColumn('role')}
items={['Manager', 'Senior', 'Junior', 'Lead', 'Intern']}
/>ColumnFacetedFilter
Multi-select dropdown filter with faceted value counts.
<ColumnFacetedFilter
title="Role"
column={table.getColumn('role')}
items={['Manager', 'Senior', 'Junior', 'Lead', 'Intern']}
/>FilterGroup
Dynamic filter management component that allows adding/removing filters (ColumnFilter).
<FilterGroup
table={table}
items={[
{
key: 'department',
lable: 'Department',
items: ['Engineering', 'Marketing', 'Sales']
},
{
key: 'location',
lable: 'Location',
items: ['New York', 'London', 'Tokyo']
}
]}
/>ColumnToggle
Dropdown menu for showing/hiding table columns.
<ColumnToggle table={table} />Pagination
Comprehensive pagination controls with page size selection.
<Pagination table={table} />Note: items array is of itemsT type, so you can pass allowed data. DataTable fully customizable with column array itself.
Reference
ColumndFilter and ColumnFacetedFilter
Prop
Type
ColumnHeader
Prop
Type
ColumnSorter
Prop
Type
ColumnToggle and Pagination
Prop
Type
useDataTable
Prop
Type
DataTable
Prop
Type
DataTableVirtualized
Prop
Type