Default Layouts

View as Markdown

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 Aggregations
  • gridOptions - 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: undefined

boolean | AutoCreateLayoutOptions

Create a first-run Layout from AG Grid ColDefs (when no Layouts are provided)

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
Auto-create Layout
Fork
  • This example sets autoCreateLayout: true and provides no Layout in Initial State
  • AdapTable builds a Default Layout from the ColDefs:
    • Name is pinned left and sorted ascending
    • License and Description are hidden (hide: true)
    • Id is hidden
Try It Out
  • Open the Layout Toolbar and note the current Layout is named Default Layout
  • Show License or Description from the Columns Tool Panel — they sit in ColDef order
Loading demo…

Row Grouping & Aggregations

The auto-created default Layout can include Row Grouping and Aggregations if they are provided in the AG Grid definitions.

Auto-create Grouped Layout
Fork
  • 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 — sum
    • Github Watchers — sum
    • Open Issues — avg
Try It Out
  • Open the Layout Toolbar and note the current Layout is named Default Layout
  • The Columns Tool Panel shows Language in Row Groups and the three value columns
Loading demo…

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 pivotMode in GridOptions is set to true
  • Setting pivot or pivotIndex on ColDefs is not enough — without pivotMode AdapTable creates a Table Layout
Auto-create Pivot Layout
Fork
  • This example shows how to create a Pivot Default Layout with Pivot Columns, Grouped Rows and Aggregations
  • pivotMode is set to true in GridOptions — that is what makes this a Pivot Layout
  • The ColDefs then supply the Pivot contents:
    • License is a pivot column (pivot: true)
    • Language is row-grouped (rowGroup: true)
    • Github Stars and Github Watchers are summed
Try It Out
  • Open the Layout Toolbar and note the current Layout is a Pivot Layout named Default Layout
  • The Columns Tool Panel shows Language in Row Groups, License in Pivot and the two value columns
Loading demo…

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

Rebuild Layout Every Load
Fork
  • This example sets autoCreateLayout: { name: 'Overview', createEveryLoad: true }
  • A persisted Overview Layout is loaded with only Name and Language visible
  • Because createEveryLoad is 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 Layout button in the custom Toolbar restores that same ColDef snapshot — the same thing createEveryLoad does on the next load
Try It Out
  • Hide a column, change the sort, or clear the Language filter
  • Click Reload Layout in the Buttons Toolbar — those changes are discarded and the ColDef Layout (plus the TypeScript filter) is shown again
Loading demo…

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 autoCreateLayout also receive these properties (ColDef values win when both set same field)

This is done using the layoutCreationDefaultProperties property in Layout Options.

layoutCreationDefaultProperties

Sets default properties for new Layouts (Table or Pivot)
Default Creation Props
Fork
  • In this example we have provided default creation properties for both Table and Pivot Layouts:
    • For Table Layouts - we default a on Name Column, and a Column Filter on Language Column
    • For Pivot Layouts - we default Aggregations on Github Stars and Github Watchers Columns (suppressing the Agg Func), a GrandTotalRow at bottom and a PivotGrandTotal Column before
Try It Out
  • 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
Loading demo…

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 dynamically
  • saveState - controls how Layouts are persisted to avoid polluting the saved state with default configurations
Default Layout Props
Fork
  • This example demonstrates how to create default layout properties in Initial State; we:
    • Add a read-only All Columns Layout that includes all available columns with a default sort on name
    • Prevent the default All Columns Layout from being persisted by filtering it out in the saveState function in State Options
    • Apply a default descending sort on the github_stars column to all Layouts that do not contain a sort
Loading demo…