Fuaranfuaran

The source for generative UI

Editable grids with undo

A grid edit is data. A host that keeps an edit history carries each edit as the columnar op it is, in a GridEdit payload, beside the whole-rows write that every renderer already emits.

The payload

GridEdit has three members and is strict about them:

MemberMeaning
keythe State key the edit commits to
opthe edit: setCell, setColumn, insertColumn, removeColumn, appendRows or applyTransform
rowKeyFieldoptional: the grid's own row key, so a receiver can name the rows the op touched

A member outside those, an empty key, or an op the codec does not know is refused, because an edit a receiver would apply differently from the one sent is worse than one it refuses.

What a receiver derives

  • The edited table, or a refusal naming why: a row out of range, a cell of the wrong type, a missing column, and the other classes the specification lists.
  • The row delta, under the declared rowKeyField: a value edit names its one row, so a view reading the key can refresh from the edit rather than by comparing tables. With no rowKeyField the delta is the whole table and the receiver says it took the reference path.

Undo is an op

There is no second payload for undo. An undo is the GridEdit whose op is the inverse of the edit it undoes, read from the table that edit was applied to: a setCell inverts to the setCell that restores the old cell. A redo is the original op again. Two kinds have no inverse: appendRows and applyTransform, so a history that applies one cannot be undone past it. A history may be bounded, and past its bound an undo is refused, never approximated.

The evidence

  • The behaviour is pinned by the grid-edit vectors: one vector per op kind and refusal class (the edited table, the delta, the inverse and the table it restores) and three scripted undo and redo histories. The .NET, TypeScript, Python, Go and Rust hosts each run the family.
  • The format is specified in the wire format.

See it

The gallery's Undo Grid edits a five-row table, then undoes, redoes and replays the history. Its source has no undo code and no history code: its one act is turning a cell gesture into the op that names that cell.

Back to Data in the interface.