DataTableLayout

@Immutable
data class DataTableLayout(val columnWidths: Map<String, Dp> = emptyMap(), val hiddenColumns: Set<String> = emptySet(), val columnOrder: List<String> = emptyList(), val sortBy: SortState = SortState(), val multiSortBy: List<SortState> = emptyList(), val filters: Map<String, String> = emptyMap())(source)

A snapshot of how a user has arranged a table: column widths, which columns they hid, the order they put them in, the sort they left it under, and the filters they typed.

Everything a user changes about a grid is here, and nothing about the data is — a layout is keyed entirely by DataTableHeader.key, so it survives the rows being replaced, and can be saved against a user rather than against a query.

Capture one with DataTableState.captureLayout and put it back with DataTableState.applyLayout. To store it between sessions, either use encodeToString, or map these fields onto your own serializable type — they are all plain data, and Dp is a Float in dp behind Dp.value.

A layout is applied by key, so one saved before a column was added, removed, or renamed still applies: entries naming columns that no longer exist are ignored, and columns the layout has never heard of keep their declared width and sit after the ones it names.

Constructors

Link copied to clipboard
constructor(columnWidths: Map<String, Dp> = emptyMap(), hiddenColumns: Set<String> = emptySet(), columnOrder: List<String> = emptyList(), sortBy: SortState = SortState(), multiSortBy: List<SortState> = emptyList(), filters: Map<String, String> = emptyMap())

Types

Link copied to clipboard
object Companion

Reads back what encodeToString wrote.

Properties

Link copied to clipboard

Column keys in the order the user put them. Columns missing from the list follow the ones in it, in declaration order — which is where a column added since the layout was saved appears.

Link copied to clipboard

Widths the user dragged columns to. A column absent from the map keeps the width its header declares.

Link copied to clipboard

Filter queries per column. Worth dropping — layout.copy(filters = emptyMap()) — where a saved layout should restore the shape of a table but not narrow what it shows.

Link copied to clipboard

Columns the user hid. This adds to DataTableHeader.visible = false rather than overriding it: a column a caller declared unavailable stays unavailable however the layout was saved.

Link copied to clipboard

The multi-column sort in force, which takes precedence over sortBy.

Link copied to clipboard

The single-column sort in force.

Functions

Link copied to clipboard

Encodes this layout as one line-based string, for a preferences store, a database column, or a file.