Skip to content

feat(data-table): add custom header renderer#397

Open
IzumiSy wants to merge 6 commits into
mainfrom
feat/data-table-header-renderer
Open

feat(data-table): add custom header renderer#397
IzumiSy wants to merge 6 commits into
mainfrom
feat/data-table-header-renderer

Conversation

@IzumiSy

@IzumiSy IzumiSy commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Motivation

DataTable currently only exposes label for column headers, which makes common customizations like icons, partial text styling, or sort-aware header affordances awkward or impossible without forking the built-in header renderer.

This change adds a small header customization API that covers those use cases while preserving the existing built-in table header structure, sticky behavior, sort click handling, and sort indicator rendering.

Design Decision

Chosen approach

Add a header field to Column that accepts either a static ReactNode or a render function.

The render function receives a narrow HeaderRenderContext instead of the whole table/control state. That keeps the API focused on header rendering and avoids coupling column definitions to internal sort policy details.

Sort interaction

Sortable headers receive { label, sortable: true, sortDirection, activateSort }.

Non-sortable headers receive { label, sortable: false }.

This keeps the type surface explicit: custom headers can read sort state and trigger the built-in sort action when sorting is actually active, but they do not need to reimplement the sort direction cycle themselves.

Alternatives considered

A full header-cell renderer or raw sort-control API would be more flexible, but it would also make it easier to break shared behavior such as sticky headers, click targets, sort indicators, and accessibility. The smaller header API is enough for the current use cases without opening that larger escape hatch.

Summary

  • add Column.header for static or render-function-based custom header content
  • expose a discriminated HeaderRenderContext with sort-aware data and activateSort() only when sorting is active
  • keep built-in header cell layout and sort handling intact, and add tests plus a changeset for the new API

@IzumiSy
IzumiSy force-pushed the feat/data-table-header-renderer branch from a3e0543 to 60ca0a5 Compare July 23, 2026 07:58
@IzumiSy
IzumiSy marked this pull request as ready for review July 24, 2026 05:00
@IzumiSy
IzumiSy requested a review from a team as a code owner July 24, 2026 05:00
@IzumiSy

IzumiSy commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

API Design Review completed successfully!

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated by API Design Review for issue #397 · 24.7 AIC · ⌖ 6.01 AIC · ⊞ 5.8K
Comment /review to run again

Comment thread packages/core/src/components/data-table/data-table.tsx Outdated
@IzumiSy IzumiSy self-assigned this Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant