Layout persistence
ArionUI.Layout · free during the preview, also commerciallyThe state a user builds up — column widths, order and visibility, sorting, grouping, filters, summaries, conditional rules, frozen columns, zoom — captured as one object, written as JSON, and applied again on the next start.
Install
dotnet add package ArionUI.Layout --prereleaseThe package brings ArionUI.Formatting and ArionUI.Planning along, whose state a layout can carry. Capturing or applying a layout switches the module on.
Capture and apply
ArionLayout layout = grid.Api.CaptureLayout(view); // columns, sorting, grouping, filters, rules ...
string json = ArionLayoutSerializer.ToJson(layout);
// next start:
if (ArionLayoutSerializer.FromJson(json) is { } saved)
{
grid.Api.ApplyLayout(view, saved);
}Layouts name columns by key, never by position — otherwise a saved state would point at the wrong column after the user moved one. Every column needs a key from .WithKey(…), and capturing a layout throws for a column without one. Applying is tolerant: an unknown key or a missing part is skipped. A layout of a different format version is not: ApplyLayout throws NotSupportedException, and there is deliberately no migration while the preview has no installed base. Treat it as "start fresh"; LoadLayout below reports it instead of throwing.
A layout carries no theme. The theme is the application's choice, not part of what the user arranged; persist it yourself if users pick one.
Choosing what to keep
var columnsOnly = grid.Api.CaptureLayout(view, ArionLayoutParts.Columns | ArionLayoutParts.Sorting);ArionLayoutParts is a set of flags: Columns, Sorting, Grouping, Filters, Summaries, ConditionalRules, FrozenColumns, View, or All (the default).
To a file or a stream
try
{
using var file = File.OpenRead(path);
LayoutLoadResult result = grid.Api.LoadLayout(view, file);
if (!result.Succeeded) Log(result.Message ?? result.Error.ToString());
}
catch (IOException ex) // no file yet, or another I/O error: start fresh
{
Log(ex.Message);
}
// when the window closes:
using (var file = File.Create(path))
{
grid.Api.SaveLayout(view, file);
}The engine knows no file: what is saved, when and where is the application's. SaveLayout writes UTF-8 JSON into any stream and leaves it open; SaveLayoutJson and LoadLayoutJson do the same with a string. Opening the file is yours and can throw, as any file access; loading never throws for a bad layout, because a remembered layout is a convenience and losing it must not stop the window from opening: the LayoutLoadResult says Succeeded, or carries an Error (Unreadable, UnsupportedVersion, ApplyFailed) and a Message for the log.
For a planning matrix, ArionLayout.Planning has room for its date range, bucket and visible measures as a PlanningLayout. CaptureLayout does not fill it — set it from PlanningLayout.Capture(axis, measures) before saving, and rebuild the axis from it after loading; see Planning matrix. Below the grid level, view.CaptureLayout() and view.ApplyLayout(layout) work on a view alone, without frozen columns and zoom.