Skip to content
shadcn.io

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.

Framework
UI library

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

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

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.

What happens when the columns outgrow the frame?

Table sits in a container that scrolls sideways, so a table wider than the frame scrolls rather than squeezing its columns.

Do the widths stick after a refresh?

No. The widths live in the table's state and start from each column's size. Save columnSizing from onColumnSizingChange and pass it back as initial state to keep them.