EXEPERTAI LAB

Research alpha

Time Machine
EXEPERTAI LAB
GALLERY / COLLECTION
← Browse Astryx gallery
Table·hook·@astryxdesign/core

useTableColumnResize

Hook that returns a TablePlugin adding draggable resize handles to column header borders. Supports pointer + keyboard (WAI-ARIA window splitter) resizing, RTL, per-column min/max widths, and proportional-column preservation (resizes the neighbor so the table stays full-width). Commits widths on release.

Open in Playground @astryxdesign/core/Table

Signature

Call shape
useTableColumnResize()

Showcases and examples

1 documented example

useTableColumnResize — Draggable Columns

A Table using useTableColumnResize. Drag the right edge of any column header to resize; widths are committed on release. The last proportional column flexes to fill remaining space.

Preview loads on approachPreview loads on approach
Exact source · column-resize-hook-usage
// Copyright (c) Meta Platforms, Inc. and affiliates.

'use client';

import {useState} from 'react';
import {
  Table,
  useTableColumnResize,
  proportional,
  pixel,
} from '@astryxdesign/core/Table';

interface User extends Record<string, unknown> {
  id: string;
  name: string;
  email: string;
  role: string;
}

const users: User[] = [
  {
    id: '1',
    name: 'Alice Johnson',
    email: 'alice@example.com',
    role: 'Engineer',
  },
  {id: '2', name: 'Bob Smith', email: 'bob@example.com', role: 'Designer'},
  {id: '3', name: 'Charlie Brown', email: 'charlie@example.com', role: 'PM'},
  {id: '4', name: 'Diana Prince', email: 'diana@example.com', role: 'Engineer'},
  {id: '5', name: 'Eve Davis', email: 'eve@example.com', role: 'Analyst'},
];

const columns = [
  {key: 'name', header: 'Name'},
  {key: 'email', header: 'Email', width: proportional(2)},
  {key: 'role', header: 'Role', width: pixel(120)},
];

export default function ColumnResizeHookUsage() {
  const [columnWidths, setColumnWidths] = useState<Record<string, number>>({});

  const columnResize = useTableColumnResize({
    columnWidths,
    columns,
    onColumnResizeEnd: updates => {
      setColumnWidths(prev => ({...prev, ...updates}));
    },
  });

  return (
    <Table
      data={users}
      columns={columns}
      idKey="id"
      hasHover
      plugins={{columnResize}}
    />
  );
}

Usage

Hook that returns a TablePlugin adding draggable resize handles to column header borders. Supports pointer + keyboard (WAI-ARIA window splitter) resizing, RTL, per-column min/max widths, and proportional-column preservation (resizes the neighbor so the table stays full-width). Commits widths on release.

Typed props

PropType and behavior
columnWidthsRecord<string, number>
Controlled pixel-width overrides keyed by column key. When a key is present it overrides the column's declared width.
onColumnResizeEnd(updates: Record<string, number>) => void
Called when a resize completes (pointerup / Enter). Receives a map of every column key whose width changed; merge it into your columnWidths state.
minWidthnumber
Global minimum column width in pixels during resize. Overrides per-column defaults when set.
maxWidthnumber · default Infinity
Global maximum column width in pixels during resize.
columnsTableColumn<T>[]
Column definitions, needed to derive per-column min widths and detect proportional vs pixel columns for neighbor/last-column resize behavior.