Data Grid Select Column
tablecn/data-grid-select-columnFreeComponent
A reusable select column definition for the data grid with checkbox selection and shift-click support
Install it
npx shadcn@latest add https://tablecn.com/r/data-grid-select-column.jsonSource
1"use client";23import type {4 CellContext,5 ColumnDef,6 HeaderContext,7} from "@tanstack/react-table";8import * as React from "react";9import { Checkbox } from "@/components/ui/checkbox";10import { cn } from "@/lib/utils";1112type HitboxSize = "default" | "sm" | "lg";1314interface DataGridSelectHitboxProps {15 htmlFor: string;16 children: React.ReactNode;17 size?: HitboxSize;18 debug?: boolean;19}2021function DataGridSelectHitbox({22 htmlFor,23 children,24 size,25 debug,26}: DataGridSelectHitboxProps) {27 return (28 <div29 className={cn(30 "group relative -my-1.5 h-[calc(100%+0.75rem)] py-1.5",31 size === "default" && "-ms-3 -me-2 ps-3 pe-2",32 size === "sm" && "-ms-3 -me-1.5 ps-3 pe-1.5",33 size === "lg" && "-mx-3 px-3",34 )}35 >36 {children}37 <label38 htmlFor={htmlFor}39 className={cn(40 "absolute inset-0 cursor-pointer",41 debug && "border border-red-500 border-dashed bg-red-500/20",42 )}43 />44 </div>45 );46}4748interface DataGridSelectCheckboxProps49 extends Omit<React.ComponentProps<typeof Checkbox>, "id"> {50 rowNumber?: number;51 hitboxSize?: HitboxSize;52 debug?: boolean;53}5455function DataGridSelectCheckbox({56 rowNumber,57 hitboxSize,58 debug,59 checked,60 className,61 ...props62}: DataGridSelectCheckboxProps) {63 const id = React.useId();6465 if (rowNumber !== undefined) {66 return (67 <DataGridSelectHitbox htmlFor={id} size={hitboxSize} debug={debug}>68 <div69 aria-hidden="true"70 className={cn(71 "pointer-events-none absolute start-3 top-1.5 flex size-4 items-center justify-center text-muted-foreground text-xs tabular-nums transition-opacity group-hover:opacity-0",72 checked && "opacity-0",73 )}74 >75 {rowNumber}76 </div>77 <Checkbox78 id={id}79 className={cn(80 "relative transition-[shadow,border,opacity] hover:border-primary/40",81 "opacity-0 group-hover:opacity-100 data-[state=checked]:opacity-100",82 className,83 )}84 checked={checked}85 {...props}86 />87 </DataGridSelectHitbox>88 );89 }9091 return (92 <DataGridSelectHitbox htmlFor={id} size={hitboxSize} debug={debug}>93 <Checkbox94 id={id}95 className={cn(96 "relative transition-[shadow,border] hover:border-primary/40",97 className,98 )}99 checked={checked}100 {...props}101 />102// … 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 Griddata-grid | tablecn | Components | Free | 4 deps · 21 files | |
| 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 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 |
