跳到主要内容

TableHeaderCell

TableHeaderCell is the title of one column in a TableHeader, with its sort arrow and the handle that resizes it.

The Table README describes it in full.

TableHeaderCellTableHeaderCell

Props​

PropertyTypeDescription
columnTTableColumnThe column to render: its title, its sort field and callbacks, and the flags that shape the cell.
indexnumberPosition of the column, which becomes the cell's id column_<index>.
onMouseDown(event: MouseEvent<Element, MouseEvent>) => voidCalled when the resize handle is pressed.
resizable?booleanundefinedDraws the resize handle at the end of the cell.
sortedbooleanDirection of the sort; turning it off turns the arrow over.
sortBystringField the table is sorted by; the column with the same sortBy keeps its arrow visible.
defaultSize?numberundefinedWidth in pixels the column returns to when the widths are reset.
sortingVisiblebooleanShows the sort arrow and lets clicks on the title and the arrow sort the table.
tagRef?ForwardedRef<HTMLDivElement> | ((node: HTMLDivElement) => void) | undefinedRef attached to the cell when the column asks for it with withTagRef.
testId?stringundefinedValue of the cell's data-testid attribute. Default: table-header-cell.

Stories​

Default​

The title of a column the table is not sorted by; hover it to see the arrow that sorts by this column, and change any other prop live in the Controls panel below.

DefaultDefault

Resizable​

The short bar at the end of the cell is the handle a user drags to widen the column (resizable); here it only reports the press, since TableHeader does the resizing.

ResizableResizable

Sorted By This Column​

The column the table is sorted by keeps its arrow on screen without a hover, so the user sees what the list is ordered by (sortBy matches the column's sortBy).

Sorted By This ColumnSorted By This Column

Without Sorting​

A column that cannot sort: no arrow on hover and clicks on the title do nothing, for a list whose order is fixed (sortingVisible off).

Without SortingWithout Sorting

With Unchecked Checkbox​

A column with a select-all checkbox that nothing is ticked in yet shows only its title; the checkbox appears once a row is selected.

With Unchecked CheckboxWith Unchecked Checkbox

With Checked Checkbox​

The select-all checkbox before the title once every row is selected (checkbox.value); a click on it calls checkbox.onChange.

With Checked CheckboxWith Checked Checkbox

With Indeterminate Checkbox​

The same checkbox partly ticked, for a selection that covers some rows but not all (checkbox.isIndeterminate).

With Indeterminate CheckboxWith Indeterminate Checkbox

Short Column​

A narrow column, such as a row number, keeps 12 pixels before its handle instead of 22, so the title is not cut off (isShort).

Short ColumnShort Column