Data Grid
tablecn/data-gridFreeComponent
A high-performance editable data grid component with virtualization, keyboard navigation, and cell editing
Install it
npx shadcn@latest add https://tablecn.com/r/data-grid.jsonSource
1"use client";23import { Plus } from "lucide-react";4import * as React from "react";5import { DataGridColumnHeader } from "@/components/data-grid/data-grid-column-header";6import { DataGridContextMenu } from "@/components/data-grid/data-grid-context-menu";7import { DataGridPasteDialog } from "@/components/data-grid/data-grid-paste-dialog";8import { DataGridRow } from "@/components/data-grid/data-grid-row";9import { DataGridSearch } from "@/components/data-grid/data-grid-search";10import { useAsRef } from "@/hooks/use-as-ref";11import type { useDataGrid } from "@/hooks/use-data-grid";12import {13 flexRender,14 getColumnBorderVisibility,15 getColumnPinningStyle,16} from "@/lib/data-grid";17import { cn } from "@/lib/utils";18import type { Direction } from "@/types/data-grid";1920const EMPTY_CELL_SELECTION_SET = new Set<string>();2122interface DataGridProps<TData>23 extends Omit<ReturnType<typeof useDataGrid<TData>>, "dir">,24 Omit<React.ComponentProps<"div">, "contextMenu"> {25 dir?: Direction;26 height?: number;27 stretchColumns?: boolean;28}2930export function DataGrid<TData>({31 dataGridRef,32 headerRef,33 rowMapRef,34 footerRef,35 dir = "ltr",36 table,37 tableMeta,38 virtualTotalSize,39 virtualItems,40 measureElement,41 columns,42 columnSizeVars,43 searchState,44 searchMatchesByRow,45 activeSearchMatch,46 cellSelectionMap,47 focusedCell,48 editingCell,49 rowHeight,50 contextMenu,51 pasteDialog,52 onRowAdd: onRowAddProp,53 height = 600,54 stretchColumns = false,55 adjustLayout = false,56 className,57 ...props58}: DataGridProps<TData>) {59 const rows = table.getRowModel().rows;60 const readOnly = tableMeta?.readOnly ?? false;61 const columnVisibility = table.getState().columnVisibility;62 const columnPinning = table.getState().columnPinning;6364 const onRowAddRef = useAsRef(onRowAddProp);6566 const onRowAdd = React.useCallback(67 (event: React.MouseEvent<HTMLDivElement>) => {68 onRowAddRef.current?.(event);69 },70 [onRowAddRef],71 );7273 const onDataGridContextMenu = React.useCallback(74 (event: React.MouseEvent<HTMLDivElement>) => {75 event.preventDefault();76 },77 [],78 );7980 const onFooterCellKeyDown = React.useCallback(81 (event: React.KeyboardEvent<HTMLDivElement>) => {82 if (!onRowAddRef.current) return;8384 if (event.key === "Enter" || event.key === " ") {85 event.preventDefault();86 onRowAddRef.current();87 }88 },89 [onRowAddRef],90 );9192 return (93 <div94 data-slot="grid-wrapper"95 dir={dir}96// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from tablecn
All 13 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Data Grid Filter Menudata-grid-filter-menu | tablecn | Components | Free | 2 deps · 8 files | |
| Data Grid Keyboard Shortcutsdata-grid-keyboard-shortcuts | tablecn | Components | Free | 1 dep · 2 files | |
| Data Grid Row Height Menudata-grid-row-height-menu | tablecn | Components | Free | 2 deps | |
| Data Grid Select Columndata-grid-select-column | tablecn | Components | Free | 1 dep | |
| Data Grid Skeletondata-grid-skeleton | tablecn | Components | Free | no deps | |
| Data Grid Sort Menudata-grid-sort-menu | tablecn | Components | Free | 2 deps · 4 files | |
| Data Grid View Menudata-grid-view-menu | tablecn | Components | Free | 2 deps · 2 files | |
| Data Tabledata-table | tablecn | Components | Free | 3 deps · 17 files |
