DataTableState

@Stable
class DataTableState(lazyListState: LazyListState, horizontalScrollState: ScrollState)(source)

State holder for DataTable.

Provides programmatic access to scroll position, focused row and cell, cell editing, and column widths. Create via rememberDataTableState.

Constructors

Link copied to clipboard
constructor(lazyListState: LazyListState, horizontalScrollState: ScrollState)

Properties

Link copied to clipboard

Column keys in the order the user put them, or empty while they are in declared order.

Link copied to clipboard

Message from DataTableHeader.validateEdit rejecting the last attempted commit, or null.

Link copied to clipboard

The cell being edited, or null when no editor is open.

Link copied to clipboard

Index of the first visible item in the vertical list.

Link copied to clipboard

The focused cell, or null while focus is on a whole row or nowhere at all.

Link copied to clipboard

DataTableHeader.key of the column that currently has keyboard focus, or null when focus is on a whole row rather than a cell.

Link copied to clipboard

Key of the row that currently has keyboard focus, or null when no row is focused.

Link copied to clipboard

Columns the user has hidden, by DataTableHeader.key.

Link copied to clipboard

Whether an editor is currently open. Editing always happens at focusedCell.

Link copied to clipboard

The selected block of cells, or null when nothing is anchored.

Link copied to clipboard

The cell a range selection is anchored to — the corner that stays put while the cursor moves — or null when only a single cell is selected.

Functions

Link copied to clipboard
suspend fun animateScrollToItem(index: Int, scrollOffset: Int = 0)

Animates scrolling so that the given item index is visible.

Link copied to clipboard

Puts a captured layout back.

Link copied to clipboard

Closes any open editor, discarding what was typed. Reports the abandoned edit to DataTable's onEditCancel.

Link copied to clipboard

Captures how the table is arranged right now: widths, hidden columns, order, sort, and filters.

Link copied to clipboard

Collapses the selection back to the single focused cell.

Link copied to clipboard
fun extendRangeTo(rowKey: Any, columnKey: String)

Extends the selection to one cell, the way Shift+click does.

Link copied to clipboard
fun focusCell(rowKey: Any?, columnKey: String?)

Moves keyboard focus to one cell, or clears it when either key is null.

Link copied to clipboard
fun focusRow(key: Any?)

Moves keyboard focus to the row with the given key, or clears focus when key is null.

Link copied to clipboard
fun isCellInRange(rowKey: Any, columnKey: String): Boolean

Whether one cell falls inside the selected range.

Link copied to clipboard

Whether the user has hidden this column. Says nothing about DataTableHeader.visible, so a column can be shown by this and still not be rendered.

Link copied to clipboard
fun moveColumn(key: String, toIndex: Int)

Moves one column to a position among the others, the way dragging its header would.

Link copied to clipboard

Clears all user-resized column widths, reverting to header-defined or weighted widths.

Link copied to clipboard

Drops every column override — widths, hidden columns, and order — leaving the table as its headers declare it.

Link copied to clipboard
suspend fun revealFocusedCell()

Scrolls both axes so the focused cell is on screen. No-op when nothing is focused.

Link copied to clipboard
suspend fun scrollToItem(index: Int, scrollOffset: Int = 0)

Scrolls the table so that the given item index is visible.

Link copied to clipboard

Selects the block of cells between two corners, leaving the cursor on focus.

Link copied to clipboard
fun setColumnHidden(key: String, hidden: Boolean)

Hides or shows one column, by DataTableHeader.key.

Link copied to clipboard
fun startEditing(rowKey: Any, columnKey: String)

Opens the editor on one cell, as Enter or F2 would.