Data grid / foldkit-data-grid

Selection

Selection is the grid's and opt-in: DataGrid.make({ id, columns, rowSelection: 'multiple', cellSelection: true }). Without the options the selection Messages change nothing.

ts
import { GridSelection } from 'foldkit-data-grid'

const Picking = DataGrid.make({ id: 'picking', columns, rowSelection: 'multiple' })
const start = Picking.bundle.init(undefined).model
const picked = Picking.bundle.update(start, Picking.Message.RowSelected({ row: 'p1' }), undefined).model
GridSelection.isSelected(picked.selection.rows)('p1') // true
  • Rows are a RowSelection: Keys({ keys }), or AllExcept({ except }) after AllRowsSelected, so select-all holds every row whether loaded or counted at all. RowSelected toggles a row in 'multiple' mode and is the selection in 'single' mode; either way it becomes the anchor. RowsExtended({ rows, to }) adds a Shift range the view worked out with GridSelection.rowsBetween; RowsCleared empties it.
  • A Shift click in a 'multiple' grid without cellSelection focuses the cell and reports Out.RowsRequested({ from, to }): from the anchor, or the row focused before it, to the row clicked. A click reaches the grid through a Mount, which cannot read the rows the view last drew, so the application, which holds them, adds the range: Grid.extendRows(rows, model.grid, request) is the grid's Model with it added, the rows between taken in the order they are drawn. With cellSelection, a Shift click spans cells instead.
  • Cells are one rectangle, CellsSelected({ anchor, focus }), named by its corners, so it survives a re-sort as the same two cells and GridSelection.boxOf(projection, range) is what it covers now. A plain click or key (Focused, Moved) lets it go: one focused cell is the default selection. GridSelection.extend is the range a Shift key makes. Grid.rangeSize(rows, model.grid) is Some({ rows, columns, cells }) for the range the Model holds now (hidden columns left out), or none with no range or a corner no longer shown: what a status line counts.
  • GridSelection.isSelected(selection) indexes a selection once; call it once per render, not per row.