Default Layouts
Summary
- AdapTable can create a first-run Layout from AG Grid ColDefs when none are provided
- That Layout can optionally be rebuilt from ColDefs on every load
- Default Layout properties can be applied to all Layouts created at run-time
- State Options can extend all Layouts (new and existing) at design-time
AdapTable requires a Current Layout, and the vast majority of users ship one in Initial Adaptable State.
However sometimes this feels like overkill or unnecessary repitition.
For instance the Layout might be identical to properties already provided in AG Grid GridOptions and ColDefs.
Other users create multiple Layouts and want a way for the same base set of properties to exist on each.
While another use case wishes to easily patch Layouts that have been created.
AdapTable provides a solution for each of these use cases by allowing developers to:
- define a first-run Layout from AG Grid ColDefs and GridOptions
- apply default properties to be added to all Layouts created at runtime
- patch Layouts as they load
Auto-creating Default Layout
Developers can ask AdapTable to create a default Layout in place of providing one themselves.
Hint
This is particularly useful if the Layout will be identical to the properties provided in ColDefs and GridOptions
This is configured using the autoCreateLayout property in Layout Options.
Note
- Developers have the option to provide a custom name for the default Layout
- If no name is provided, then the Layout is named "Default Layout"
AdapTable will create a new Layout using 2 sets of AG Grid properties:
columnDefs- Order, Visibility, Sizing, Pinning, Sorts, Row Grouping, Pivoting and AggregationsgridOptions-defaultColDef, Pivot Mode, Row Model
Note
- Any Default Creation Properties which have been provided are also applied when creating the default Layout
- ColDef values win when both set same field
AdapTable will only create a Default Layout if there are no other Layouts provided in State (unless the createEveryLoad property is set - see below).
Caution
If autoCreateLayout is set to true, but other Layouts are in Initial or Persisted State, no Default Layout is created
autoCreateLayout
Default: undefinedboolean | AutoCreateLayoutOptions
Persisting
The auto-created Layout persists into AdapTable State like any other Layout or other AdapTable object.
The Layout will then load with changes the next time AdapTable opens and it is treated like any other object.
Note
- The exception to this rule is if the Layout is configured to re-create on every load (see below)
- When this happens the Layout is still persisted, but the next load will re-create the Layout, overriding any changes
- This example sets
autoCreateLayout: trueand provides no Layout in Initial State - AdapTable builds a
Default Layoutfrom the ColDefs:Nameis pinned left and sorted ascendingLicenseandDescriptionare hidden (hide: true)Idis hidden
- Open the Layout Toolbar and note the current Layout is named
Default Layout - Show
LicenseorDescriptionfrom the Columns Tool Panel — they sit in ColDef order
Row Grouping & Aggregations
The auto-created default Layout can include Row Grouping and Aggregations if they are provided in the AG Grid definitions.
- This example shows how to create a Default Layout that includes Row Groups and Aggregations
- The ColDefs group by
Language(rowGroup: true) and aggregate:Github Stars—sumGithub Watchers—sumOpen Issues—avg
- Open the Layout Toolbar and note the current Layout is named
Default Layout - The Columns Tool Panel shows
Languagein Row Groups and the three value columns
Pivot Layouts
The auto-created default Layout can be a Pivot Layout (rather than a Table Layout).
Note
- A Pivot Layout is created only when
pivotModein GridOptions is set to true - Setting
pivotorpivotIndexon ColDefs is not enough — withoutpivotModeAdapTable creates a Table Layout
- This example shows how to create a Pivot
Default Layoutwith Pivot Columns, Grouped Rows and Aggregations pivotModeis set to true in GridOptions — that is what makes this a Pivot Layout- The ColDefs then supply the Pivot contents:
Licenseis a pivot column (pivot: true)Languageis row-grouped (rowGroup: true)Github StarsandGithub Watchersare summed
- Open the Layout Toolbar and note the current Layout is a Pivot Layout named
Default Layout - The Columns Tool Panel shows
Languagein Row Groups,Licensein Pivot and the two value columns
Recreate Every Grid Load
The Default Layout can be configured to be created every time AdapTable loads.
This is done by setting createEveryLoad to true in autoCreateLayout.
autoCreateLayout: { name: 'Overview', createEveryLoad: true }When this happens, changes made to the Layout in the previous session (and persisted into State), are ignored.
If other Layouts exist but the named Layout is still present, that named Layout is recreated; the other Layouts are left unchanged.
If name is omitted, createEveryLoad still targets Default Layout.
Caution
If the named Layout was deleted and other Layouts are present in State, the default Layout is not auto-created
- This example sets
autoCreateLayout: { name: 'Overview', createEveryLoad: true } - A persisted
OverviewLayout is loaded with onlyNameandLanguagevisible - Because
createEveryLoadis true, that Layout is replaced from ColDefs on load — so all ColDef columns appear - Default creation properties also add a Column Filter on
Language - The
Reload Layoutbutton in the custom Toolbar restores that same ColDef snapshot — the same thingcreateEveryLoaddoes on the next load
- Hide a column, change the sort, or clear the
Languagefilter - Click
Reload Layoutin the Buttons Toolbar — those changes are discarded and the ColDef Layout (plus the TypeScript filter) is shown again
Default Creation Properties
Default creation properties are applied automatically to all new Table and Pivot Layouts created at runtime.
These properties ensure consistency across newly created Layouts without requiring manual configuration.
Note
- Layouts created through Layout API will contain these properties (unless property is explicitly overridden)
- Layouts created via the UI wil show these properties in Layout Wizard (allowing user to change them)
- Layouts created by
autoCreateLayoutalso receive these properties (ColDef values win when both set same field)
This is done using the layoutCreationDefaultProperties property in Layout Options.
layoutCreationDefaultProperties
- In this example we have provided default creation properties for both Table and Pivot Layouts:
- For Table Layouts - we default a on
NameColumn, and a Column Filter onLanguageColumn - For Pivot Layouts - we default Aggregations on
Github StarsandGithub WatchersColumns (suppressing the Agg Func), a GrandTotalRow at bottom and a PivotGrandTotal Column before
- For Table Layouts - we default a on
- In the Layout Toolbar click to add a new Table Layout and note that the new Layout already contains the Column Sort and Column Filter defined in default props
- Then click to add a new Pivot Layout and note that the new Layout already contains the Aggregations, GrandTotalRow and PivotGrand Total Column
Patching Initial State Layouts
AdapTable allows developers to enhance all Layouts (new and existing) by manipulating the Layout State.
This is most easily achieved by leveraging 2 State Options functions:
applyState- modifies the Layout state dynamicallysaveState- controls how Layouts are persisted to avoid polluting the saved state with default configurations
- This example demonstrates how to create default layout properties in Initial State; we:
- Add a read-only
All ColumnsLayout that includes all available columns with a default sort onname - Prevent the default
All ColumnsLayout from being persisted by filtering it out in thesaveStatefunction in State Options - Apply a default descending sort on the
github_starscolumn to all Layouts that do not contain a sort
- Add a read-only