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
| Core | Skin (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 width | header 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
labelLargeonsurfaceContainerHigh, rows 52 tall, a 1 dpoutlineVariantdivider, the selected rowsecondaryContainer.
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,onSurfaceVarianttypography.labelLarge(header),bodyMedium(cells)spacing.mcell padding,spacing.lside 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.
| Field | Type | Material default | What it's for |
|---|---|---|---|
density | Density | Standard | row height 52 / 40 / 32 |
striped | Boolean | false | alternate row fill |
stickyHeader | Boolean | true | header stays while the rows scroll |
dividers | Boolean | true | lines between rows |
headerStyle / cellStyle | CamoTextStyle | labelLarge / bodyMedium | text |
sortIcon | IconSource | arrow up | rotates for descending |
colors | TableColors(header, row, selectedRow, divider, text, headerText) | M3 values | every color it uses |
strings | TableStrings | English | "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
CamoColumn,TableSort,TableTheme/Style, state, slots, renderer, theCamoSkinfield.CamoDataTable(lazy rows, sticky header, width resolving), the DebugSkin renderer.- 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
CamoPaginationby touch, keyboard and screen reader.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Case | Decided behavior |
| --- | --- |
| Columns wider than the window | The table scrolls horizontally; the header scrolls with it. |
| Sorting | The app sorts rows; the table only reports onSortChange and shows the arrow. |
| No rows | empty shows in the body; with loading, skeleton rows. |
| RTL | Columns and alignment mirror. |
- The renderer has five parts:
Container,HeaderRow,HeaderCell,RowandCell; core sizes the columns once, so the header and every row line up.TableThemehasheaderHeight,rowHeight,cellPadding,striped,dividers,headerStyle,cellStyle,sortIconandTableColors(container, header, row, stripedRow, selectedRow, divider, text, headerText); density and built-in strings are not built. - Column widths are
FixedorWeight(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, unlessonRowClickis 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:
emptyfills the body of an empty table; withloadingand 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.
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-resizepointer on desktop); double-click fits the content to the widest of the rows currently composed; each column keeps itsminWidth; 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,reorderinganddropTarget(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, thenWeightover the rest,Contentfrom a measured max of the visible rows); a sharedTableLayoutobject gives each row the same widths. - Semantics:
collectionInfo(rowCount, columnCount)on the list,collectionItemInfoandisTraversalGroupper row; header cellsRole.ButtonwithstateDescriptionfor the sort. - Keys use
rememberRovingFocusover rows; Spacetoggleable.
4. Build steps
- Widths, the list, header and rows, selection and sort, the renderer.
- 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
| Case | Decided behavior |
|---|---|
| Variable row height | Rows measure their own height (min = density). |
CamoColumn(key, header, width, align, sortable, cell); rows are aLazyColumn(itemsIndexedwith the row key) and each carriescollectionItemInfo; the header and the cells shareModifier.weightorModifier.width.
- None specific.