shadcn.io is not affiliated with official shadcn/ui
Data Table examples · Advanced
Resizable Columns Data Table for React
A table of employees whose columns resize when you drag their edges.
Four employees in five columns, each with a handle on its trailing edge. Drag a handle and the column widens or narrows as you move; TanStack Table's column sizing keeps the widths. Use it for wide tables where people need room for one column, such as long emails or descriptions.
Preview
Installation
FAQ
How does a column resize?
useTable gets columnResizingFeature, columnSizingFeature and columnResizeMode: "onChange", so the width updates while you drag. The handle calls header.getResizeHandler() from onMouseDown and onTouchStart.
How is the starting width set?
Each column sets size: Name 150, Department 120, Position 180, Email 220 and Salary 120. Heads and cells take getSize() as their width, and the table takes table.getTotalSize() with table-fixed, so a cell's text is cut off with an ellipsis instead of widening its column.
What is the drag handle?
A thin div on the end edge of each TableHead, with cursor-col-resize. It shows on hover and turns bg-primary while header.column.getIsResizing() is true. The note under the table says to drag column edges.
Can I resize a column from the keyboard?
Not in this demo: the handle answers the pointer and touch only, and it's hidden from screen readers. For keyboard resizing, add buttons or keys that call column.setSize or table.setColumnSizing.
Related
- Basic Data Table with CheckboxesA table of products with a checkbox on
- Data Table with Column VisibilityA table of orders with a Columns menu
- Expandable Sub-Rows Data TableA table of projects where each row
- Data Table with FiltersA table of users with two inputs that
- Data Table with ActionsA table of payments with a menu of
- Paginated Data TableA table of transactions, five per page