Skip to main content

CamoDataTable

Concept​

1. Why​

A data table shows rows of records in typed columns with sorting, selection and an optional footer: an admin list of users, orders, files (Material and Fluent DataGrid / Table, Carbon's data table, macOS table views). It is not a list (CamoListItem, one row, a few fields) and not a spreadsheet (no cell editing in v0.1). Paging is CamoPagination beside it; the table never fetches.

2. Shape​

Split of duties

CoreSkin (renderer)
the column model and widths, lazy rows, sort and selection state flow (app-owned), the header sort buttons, keyboard (Up and Down between rows, Space toggles, Enter activates), semantics (grid, header cells, "row 3 of 40"), sticky header, horizontal scroll when the columns need more than the widthheader and row look, zebra and hover, selected row, the sort arrow, cell padding and density, dividers

Material mapping preview: the M3 has no data table; Material's own is a list-like layout.

  • Header labelLarge on surfaceContainerHigh, rows 52 tall, a 1 dp outlineVariant divider, the selected row secondaryContainer.

3. API​

Contract​

data class CamoColumn<T>(
val key: Any,
val header: String,
val width: ColumnWidth = Weight(1f), // Fixed(dp) | Weight(w) | Content
val align: ColumnAlign = Start, // Start | Center | End (numbers)
val sortable: Boolean = false,
val cell: @Composable (T) -> Unit,
)

fun <T> CamoDataTable(
columns: List<CamoColumn<T>>,
rows: List<T>,
rowKey: (T) -> Any,
sort: TableSort? = null, // TableSort(columnKey, ascending); the app sorts rows
onSortChange: ((TableSort) -> Unit)? = null,
selection: Set<Any>? = null, // null: not selectable; otherwise the selected row keys
onSelectionChange: ((Set<Any>) -> Unit)? = null,
onRowClick: ((T) -> Unit)? = null,
empty: Slot? = null, loading: Boolean = false, footer: Slot? = null,
caption: String, // names the table for screen readers
)

State → renderer: TableState(columnCount, rowCount, selectable, loading); HeaderCellState(sortDirection?, sortable, align, interaction); RowState(index, selected, interaction, striped); CellState(align). Slots: the cell content. The renderer has Container, HeaderRow, HeaderCell, Row and EmptyState parts.

Tokens used​

  • colors.surface, surfaceContainerHigh (header), outlineVariant, secondaryContainer (selected), onSurface, onSurfaceVariant
  • typography.labelLarge (header), bodyMedium (cells)
  • spacing.m cell padding, spacing.l side padding

Component theme​

theme.components.data table. Every field is nullable in the theme. The skin's defaults(theme) fills whatever isn't set (Material defaults shown). See Theme §3.10.

FieldTypeMaterial defaultWhat it's for
densityDensityStandardrow height 52 / 40 / 32
stripedBooleanfalsealternate row fill
stickyHeaderBooleantrueheader stays while the rows scroll
dividersBooleantruelines between rows
headerStyle / cellStyleCamoTextStylelabelLarge / bodyMediumtext
sortIconIconSourcearrow uprotates for descending
colorsTableColors(header, row, selectedRow, divider, text, headerText)M3 valuesevery color it uses
stringsTableStringsEnglish"sorted ascending", "select row", "loading"

Accessibility​

  • A grid: a caption, a header row of column headers (sortable ones are buttons announcing "Name, sorted ascending"), rows with row and column indexes ("row 3 of 40").
  • One Tab stop into the body; Up and Down move between rows, Home and End jump, Space toggles selection, Enter runs onRowClick; Left and Right scroll when the columns overflow.
  • Selection announces "selected"; the select-all checkbox in the header has its own label.

4. Build steps​

  1. CamoColumn, TableSort, TableTheme / Style, state, slots, renderer, the CamoSkin field.
  2. CamoDataTable (lazy rows, sticky header, width resolving), the DebugSkin renderer.
  3. Tests: width resolving (fixed, weight, content), sort callback and arrow, selection modes and select-all, keyboard, empty and loading, semantics, 1000 rows stay lazy.

Done when

  • The admin sample's sortable, selectable table pages through CamoPagination by touch, keyboard and screen reader.

5. Edge cases​

CaseDecided behavior
CaseDecided behavior
------
Columns wider than the windowThe table scrolls horizontally; the header scrolls with it.
SortingThe app sorts rows; the table only reports onSortChange and shows the arrow.
No rowsempty shows in the body; with loading, skeleton rows.
RTLColumns and alignment mirror.
Changed in the M10 build (2026-11-02)
  • The renderer has five parts: Container, HeaderRow, HeaderCell, Row and Cell; core sizes the columns once, so the header and every row line up. TableTheme has headerHeight, rowHeight, cellPadding, striped, dividers, headerStyle, cellStyle, sortIcon and TableColors (container, header, row, stripedRow, selectedRow, divider, text, headerText); density and built-in strings are not built.
  • Column widths are Fixed or Weight (a share of what the fixed columns leave). Content-measured widths, horizontal scrolling, column resizing and row expansion are not built. The header sits above the lazy body, so it stays put; the table needs a height.
  • Sorting: a click on a sortable header calls onSortChange (a new column sorts ascending; the sorted one flips); the app sorts the rows. Selection: a click or Space toggles the row, unless onRowClick is set (then a click calls it); the select column holds a checkbox per row and a select-all in the header (checked only when every row is; no indeterminate state yet). Up and Down move between rows; focus only moves among the rows that are composed.
  • States: empty fills the body of an empty table; with loading and no rows a progress circle shows, and the table announces "Loading".
  • Cell editing, column resizing and reordering, row expansion and frozen columns are v0.2.
  • Selection is a set of keys the app owns (like CamoChipGroup); say if you want a built-in single-select mode.
Resizable, hideable and reorderable columns (M16, 2026-11-17, srctool/camouflage#72)

Desktop tables let the user resize, hide and reorder columns (Graft's commit graph columns, file and PR lists).

class CamoColumnState(columns: List<Any>) { // app-owned, like CamoSplitState
val order: List<Any>; val widths: Map<Any, Dp>; val hidden: Set<Any>
fun resize(column: Any, to: Dp); fun move(column: Any, to: Int); fun hide(column: Any); fun show(column: Any)
fun reset(); fun snapshot(): CamoColumnSnapshot; fun apply(snapshot: CamoColumnSnapshot)
}
CamoDataTable(..., columnState: CamoColumnState? = null) // null: the table as today
CamoColumn(..., minWidth: Dp = 48.dp, resizable: Boolean = true, hideable: Boolean = true, reorderable: Boolean = true)
  • Resize: drag the header's trailing edge (an 8 dp grab area, a col-resize pointer on desktop); double-click fits the content to the widest of the rows currently composed; each column keeps its minWidth; a column the user never resized keeps its flexible width, and "Reset widths" returns the rest.
  • Hide and show: a header context menu (right-click, and the Menu key or Shift+F10 on a focused header) lists "Hide column" and a "Columns" submenu with a checkbox per column (the submenu from M16); the last visible column cannot be hidden.
  • Reorder: drag a header; the drop position shows as a line; by keyboard, Alt+Left and Alt+Right move the focused column, Ctrl+Left and Ctrl+Right resize it by a key step.
  • Semantics: a header exposes the actions "Widen", "Narrow", "Move left", "Move right" and "Hide", so a screen reader can do everything a mouse can.
  • No new renderer: the header cell's state gains resizable, resizing, reordering and dropTarget (defaulted); the renderer draws the grab line and the drop line.

Open for review: (1) reorder in scope now? Proposed: yes, all three at once: they share the header interaction and the state object, and the issue asks for all three; (2) widths in dp (not fractions): columns are content, and a saved layout should keep a readable width; (3) where the state lives: the table takes columnState, the app persists snapshot(); Camouflage stores nothing.

Implementation​

1. Why​

Compose has no table; LazyColumn with stickyHeader is the right base. Columns are laid out by a shared width resolver so the header and every row line up.

2. Shape​

3. API​

@Composable public fun <T> CamoDataTable(columns: List<CamoColumn<T>>, rows: List<T>, rowKey: (T) -> Any, caption: String,
modifier: Modifier = Modifier, sort: TableSort? = null, onSortChange: ((TableSort) -> Unit)? = null,
selection: Set<Any>? = null, onSelectionChange: ((Set<Any>) -> Unit)? = null, onRowClick: ((T) -> Unit)? = null,
empty: (@Composable () -> Unit)? = null, loading: Boolean = false, footer: (@Composable () -> Unit)? = null)
  • Widths resolve once per layout (Fixed, then Weight over the rest, Content from a measured max of the visible rows); a shared TableLayout object gives each row the same widths.
  • Semantics: collectionInfo(rowCount, columnCount) on the list, collectionItemInfo and isTraversalGroup per row; header cells Role.Button with stateDescription for the sort.
  • Keys use rememberRovingFocus over rows; Space toggleable.

4. Build steps​

  1. Widths, the list, header and rows, selection and sort, the renderer.
  2. Tests: widths, sort, selection, keys, 1000-row laziness, semantics.

Done when

  • Works by touch, mouse, keyboard and screen reader on all targets.

5. Edge cases​

CaseDecided behavior
Variable row heightRows measure their own height (min = density).
Changed in the M10 build (2026-11-02)
  • CamoColumn(key, header, width, align, sortable, cell); rows are a LazyColumn (itemsIndexed with the row key) and each carries collectionItemInfo; the header and the cells share Modifier.weight or Modifier.width.
  • None specific.