Callbacks & persistence
Overview
WebGridCanvas exposes 4 callbacks for reacting to user-driven mutations.
They're the primitives you need to persist grid state to localStorage,
a backend, or any external sink. The grid itself never persists — that
choice is left to the caller.
Available callbacks
Persisting column layout
set_on_columns_changed fires after every layout-mutating command.
Combine with the 3 layout readers to snapshot the state.
Readers
Example: localStorage
On mount, read the stored JSON and apply it by:
- Widths — set
ColumnDef.widthbefore building theGridModel - Order — sort
model.columnsto match the persisted order - Pinned count — set
model.pinned_countdirectly (or viaset_pinned_countafter mount)
After mutating widths or order in model.columns, recompute the precomputed
offsets used by hit-testing:
The examples/basic-leptos/src/lib.rs example ships a complete
load/save/apply flow you can copy.
Scope of set_on_columns_changed
The callback covers physical layout only: widths, order, pin count.
It does not fire on ToggleSort, SetSort, ClearSort,
SetColumnFilter, or ClearAllFilters — those have no dedicated
callback yet. Persist sort/filter state separately if you need it.
It also fires on CommitColumnResize (once at mouseup), not on every
intermediate ResizeColumn during a drag — so writes to localStorage
stay infrequent without any throttling on your side.
Re-entrancy
⚠️ Do not dispatch a GridCommand synchronously from any callback.
The callback runs while the grid's internal state is still borrowed
read-only — dispatching would re-borrow and panic. Defer via
queueMicrotask, setTimeout(0), or a channel if you need to react
with another command.