AyCode.Blazor/AyCode.Blazor.Components/docs/MGGRID/MGGRID_LAYOUT.md

1.9 KiB

MgGrid — Layout Persistence

Part of the MgGrid system. See README.md for overview and component hierarchy.

Storage Keys

Grid layouts are stored in localStorage with structured keys:

AutoSave: {AutoSaveLayoutName}_{MasterOrParentTypeName}_AutoSave_{UserId}
UserSave: {AutoSaveLayoutName}_{MasterOrParentTypeName}_UserSave_{UserId}
Splitter: Splitter_{grid.AutomaticLayoutStorageKey}

Examples:

GridOrder_Master_AutoSave_42          ← master grid, user #42
GridOrder_Order_AutoSave_42           ← detail grid under Order parent
GridOrder_Master_UserSave_42          ← manually saved layout
Splitter_GridOrder_Master_AutoSave_42 ← splitter pane size

Three Layout Tiers

Tier Key Contains When Saved When Loaded
Default (in-memory _defaultLayoutJson) First LayoutAutoLoading — captures layout before any load ResetLayoutAsync() — restores original
AutoSave _AutoSave_ Every LayoutAutoSaving event (on any layout change) Every LayoutAutoLoading event (on grid init, wrapped in BeginUpdate/EndUpdate)
UserSave _UserSave_ SaveUserLayoutAsync() — explicit user action LoadUserLayoutAsync() — explicit user action

Layout Operations

Method Behavior
SaveUserLayoutAsync() Saves current layout to both UserSave AND AutoSave keys
LoadUserLayoutAsync() Loads from UserSave key (if exists)
ResetLayoutAsync() Removes AutoSave key, restores in-memory _defaultLayoutJson
HasUserLayoutAsync() Checks if UserSave key exists in localStorage

Persisted State

The layout (GridPersistentLayout) includes: column order, column widths, sort descriptors, group descriptors, filter row values, page size — serialized as JSON via System.Text.Json.

User Identification

GetLayoutUserId() is virtual — defaults to 0. Override in project adapter to provide the logged-in user's ID.