# Layouts

Canonical page: https://www.adaptabletools.com/docs/handbook-layouts

- AdapTable uses Layouts to manage sets of **columns** and column-related information
- Layouts are designed to enable users easily to switch between different column setups in their grid
- Layouts typically contain column visibility and order information but can also include details about column:
  - sorting
  - row grouping and aggregations
  - column and grid filters
  - size / widths
  - pinning
- Users can create 2 types of Layouts:
  - Table Layouts - standard rows and columns
  - Pivot Layouts - displayed when AG Grid is in Pivot Mode and showing pivoted data
- At least **one Layout must be provided** - either in Initial Adaptable State or via auto-creation
- There is always a Current Layout which defines how a Grid looks
- Objects from other Modules e.g. Styles can be extended to specific Layouts

Layouts are the primary way in AdapTable to manage Columns and Column-related info.

They allow users to switch quickly between multiple, different, named, column set-ups in AG Grid.

- [Column Filters](https://www.adaptabletools.com/docs/handbook-column-filter/index.md) and [Grid Filter](https://www.adaptabletools.com/docs/handbook-grid-filter/index.md) manage which <b>Rows</b> are displayed in AG Grid
- Layouts specify which <b>Columns</b> are displayed

## Topics in this Section

| Topic                                                                                | Summary                                                              |
| ------------------------------------------------------------------------------------ | -------------------------------------------------------------------- |
| This page                                                                            | Overview, contents table, runtime UI, entitlements, extending, FAQ   |
| [Table Layouts](https://www.adaptabletools.com/docs/handbook-layouts-table/index.md)                   | Columns, grouping, filters, and sorting in standard (non-pivot) mode |
| [Pivot Layouts](https://www.adaptabletools.com/docs/handbook-layouts-pivot/index.md)                   | Pivot columns, row groups, aggregations, and pivot-specific options  |
| [Table Layout Wizard](https://www.adaptabletools.com/docs/handbook-layouts-wizard-table/index.md)      | Run-time steps to create and edit table layouts                      |
| [Pivot Layout Wizard](https://www.adaptabletools.com/docs/handbook-layouts-wizard-pivot/index.md)      | Run-time steps to create and edit pivot layouts                      |
| [Extending Layouts](https://www.adaptabletools.com/docs/handbook-layouts-extending/index.md)           | Scope Format Columns, Alerts, and other objects to specific layouts  |
| [Default Layouts](https://www.adaptabletools.com/docs/handbook-layouts-default/index.md)               | `autoCreateLayout` and ensuring a layout exists at startup           |
| [Updating Layouts](https://www.adaptabletools.com/docs/handbook-layouts-updating/index.md)             | Apply and change layouts programmatically                            |
| [Configuring Layouts](https://www.adaptabletools.com/docs/handbook-layouts-configuring/index.md)       | `layoutOptions`, manual persistence, Settings Panel layout preview   |
| [Synchronising Layouts](https://www.adaptabletools.com/docs/handbook-layouts-synchronising/index.md)   | Align layout state when multiple sources apply                       |
| [Monitoring Layouts](https://www.adaptabletools.com/docs/handbook-layouts-monitoring/index.md)         | Events and activity related to layout changes                        |
| [Layout Technical Reference](https://www.adaptabletools.com/docs/technical-reference-layouts/index.md) | Layout State, `layoutOptions`, and Layout API                        |

Table layout detail pages (column order, pinning, row selection, and similar) are linked from [Table Layouts](https://www.adaptabletools.com/docs/handbook-layouts-table/index.md). Pivot topics (result columns, total columns, formatting) are linked from [Pivot Layouts](https://www.adaptabletools.com/docs/handbook-layouts-pivot/index.md).

AdapTable updates Layouts automatically in response to changes being made in AG Grid.

- **Rich and powerful**: Layouts manage visibility, order, widths, pinning, sorting, grouping, aggregations, filters & more
- **One place for everything Column-related**: all column info and config lives together in a single named Layout
- **Switch views instantly**: users flip between very different Grid set-ups in 1-click from multiple places in AdapTable UI
- **Table and Pivot in 1 model**: same mechanism handles flat, row-based views & fully pivoted views
- **Complex analysis made simple**: multi-level row grouping, rich aggregations & pivoting are all saved in a Layout
- **Finance aware**: support financially useful features like [Weighted Averages](https://www.adaptabletools.com/docs/handbook-aggregation-weighted-average/index.md) out of the box
- **Always up to date**: changes in AG Grid are saved into current Layout automatically, so users never lose their set-up
- **Share across the team**: Layouts can be team-shared with colleagues, so everyone works from the same views
- **Built for every user**: developers ship pre-configured Layouts, while run-time users create and manage their own

Layouts include multiple column-related properties including row grouping, aggregations, pinning, widths etc

- AdapTable requires there is always a "Current Layout" which defines (and saves) the current Column setup
- AdapTable mandates that at least **one Layout is present** - either defined in [Initial State](https://www.adaptabletools.com/docs/technical-reference-initial-state/index.md) or set via [auto-creation](https://www.adaptabletools.com/docs/handbook-layouts-default/index.md)

By default, Layouts <b>do not include styling or formatting</b> information, i.e. all styles are available to all Layouts.

However this can be achieved, if needed, by using [Extended Layouts](https://www.adaptabletools.com/docs/handbook-layouts-extending/index.md) which can include Styles and other objects

## Table & Pivot Layouts

AdapTable provides 2 types of Layouts:

- **[Table Layouts](https://www.adaptabletools.com/docs/handbook-layouts-table/index.md)** - used when accessing AG Grid in "normal" column mode
- **[Pivot Layouts](https://www.adaptabletools.com/docs/handbook-layouts-pivot/index.md)** - opens AG Grid in pivot mode displaying pivot, row-grouping and aggregation columns

**Example: Basic Layout**

Using Layouts in AdapTable

- This example contains 3 Layouts:
  - `Standard Layout` - a Table Layout containing a list of Columns
  - `Grouped Layout` - a Table Layout which is [Row Grouped](https://www.adaptabletools.com/docs/handbook-grouping-rows/index.md) by the *Language* Column and contains 2 Aggregations
  - `Pivot Layout` - a Pivot Layout with Grouping, Pivoting and Aggregations

- Switch between the 3 Layouts in the Dashboard (or Status Bar)
- Click the Layout button in the Dashboard to open the Layout Wizard
- Create a new Layout and choose which columns you would like to see

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Basic Layout',
  initialState: {
    Dashboard: {
      ModuleButtons: ['Layout'],
      PinnedToolbars: ['Layout'],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Layout'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'description',
            'open_issues_count',
            'closed_issues_count',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
        {
          TableColumns: [
            'name',
            'license',
            'open_issues_count',
            'week_issue_change',
          ],
          TableAggregationColumns: [
            {
              ColumnId: 'open_issues_count',
              AggFunc: 'sum',
            },
            {
              ColumnId: 'week_issue_change',
              AggFunc: 'max',
            },
          ],
          Name: 'Grouped Layout',
          RowGroupedColumns: ['language'],
        },
        {
          Name: 'Pivot Layout',
          PivotColumns: ['license'],
          PivotGroupedColumns: ['language'],
          PivotAggregationColumns: [
            {
              ColumnId: 'github_watchers',
              AggFunc: 'count',
            },
            {
              ColumnId: 'github_stars',
              AggFunc: 'sum',
            },
          ],
        },
      ],
    },
  },
};
```

## Layout Contents

A [Layout](https://www.adaptabletools.com/docs/technical-reference-layouts/index.md) contains a number of important column-related properties.

The Columns in the Layout can include "Special Columns" - i.e. [Calculated](https://www.adaptabletools.com/docs/handbook-calculated-column/index.md), [FreeText](https://www.adaptabletools.com/docs/handbook-freetext-column/index.md) or [Action](https://www.adaptabletools.com/docs/handbook-action-column/index.md) Columns

The contents of Table and Pivot Layouts are fairly similar, with just a few differences:

| Item                       | Table Layout | Pivot Layout |
| -------------------------- | :----------: | :----------: |
| Name                       |      ✅      |      ✅      |
| Table Columns              |      ✅      |      ❌      |
| Pivot Columns              |      ❌      |      ✅      |
| Column Visibility          |      ✅      |      ✅      |
| Column Sizing              |      ✅      |      ✅      |
| Column Sorts               |      ✅      |      ✅      |
| Column Pinning             |      ✅      |      ✅      |
| Row Groups                 |      ✅      |      ✅      |
| Expanded Row Group Info    |      ✅      |      ✅      |
| Aggregations               |      ✅      |      ✅      |
| Row Selection              |      ✅      |      ✅      |
| Column Filters             |      ✅      |      ✅      |
| Grid Filter                |      ✅      |      ✅      |
| Expanded Column Group Info |      ✅      |      ✅      |
| Row Summaries              |      ✅      |      ❌      |
| Total Rows                 |      ✅      |      ✅      |
| Total Columns              |      ❌      |      ✅      |
| SuppressAggFuncInHeader    |      ✅      |      ✅      |
| Auto Size Columns          |      ✅      |      ✅      |
| Tags & Metadata            |      ✅      |      ✅      |

See [Table Layouts](https://www.adaptabletools.com/docs/handbook-layouts-table/index.md) and [Pivot Layouts](https://www.adaptabletools.com/docs/handbook-layouts-pivot/index.md) for step by step instructions in defining the 2 types of Layouts

## Extending Layouts

By default, Layouts are simply sets of column visibility, order and related column properties.

They do not include other [Adaptable Objects](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-initial-state/index.md#adaptable-objects), and everything in [Adaptable State](https://www.adaptabletools.com/docs/dev-guide-adaptable-state/index.md) is available in all Layouts.

In other words, Layouts **do not include styling or formatting** information nor have a concept of Scope

For some use cases this can be too restrictive - users might require some AdapTable Objects (e.g. Format Columns, Styled Columns or Alerts) to be applicable to one Layout but not to another.

Accordingly Layouts can be easily **extended** to include other objects (e.g. Styles).

See [Extending Layouts](https://www.adaptabletools.com/docs/handbook-layouts-extending/index.md) for more information on what objects can be extended and accompanying demos

## Using Layouts

Run-time access to Layouts is primarily available in the Layout section of the [Settings Panel](https://www.adaptabletools.com/docs/ui-settings-panel/index.md).

- Layouts can also be accessed and managed from the Layout [Toolbar](https://www.adaptabletools.com/docs/ui-dashboard-tabs-toolbars/index.md), [Tool Panel](https://www.adaptabletools.com/docs/ui-tool-panel/index.md) and [Status Bar](https://www.adaptabletools.com/docs/ui-status-bar/index.md)
- Many [Column](https://www.adaptabletools.com/docs/ui-column-menu/index.md) and [Context](https://www.adaptabletools.com/docs/ui-context-menu/index.md) Menu Items also provide quick access to Layout editing and related options

This displays a list of existing Layouts with buttons to edit, clone, share or delete each Layout.

There is also an `Add` button to enable run-time Users to create new Layouts via the [Layout Wizard](https://www.adaptabletools.com/docs/handbook-layouts-wizard-table/index.md).

### Special Behaviour

Because of their complexity and central importance, Layouts differ from many other AdapTable Objects in how they can be managed.

Some of the unique features of managing Layouts at run-time include:

- **Cloning**: Layouts can be cloned via a `Clone` button in each Layout; this opens the [Layout Wizard](https://www.adaptabletools.com/docs/handbook-layouts-wizard-table/index.md) with the contents cloned from the Layout but the Name of the new Layout left blank

- **Suspending**: Unlike with most Adaptable Objects, Layouts **cannot** be suspended

- **Saving**: Like all Adaptable Objects, Layouts **save automatically** when relevant changes are made in AG Grid

- **Sharing**: AdapTable will share Layouts using [Team Sharing](https://www.adaptabletools.com/docs/handbook-team-sharing/index.md)

This will also share any AdapTable objects which the Layout references, e.g. [Calculated](https://www.adaptabletools.com/docs/handbook-calculated-column/index.md) or [FreeText](https://www.adaptabletools.com/docs/handbook-freetext-column/index.md) Columns. [Referenced Team Sharing](https://www.adaptabletools.com/docs/handbook-team-sharing-referenced/index.md) additionally includes objects extended into the Layout via `LayoutExtensions`.

- **Deleting** - Layouts can be deleted (if Permissions allows) but as there must always be one Layout, AdapTable will prevent the last Layout in [Adaptable State](https://www.adaptabletools.com/docs/dev-guide-adaptable-state/index.md) being deleted

### Layout Wizards

AdapTable provides Layout Wizards to help run-time users create or edit Layouts in a series of steps.

See [Table Layout Wizard](https://www.adaptabletools.com/docs/handbook-layouts-wizard-table/index.md) or [Pivot Layout Wizard](https://www.adaptabletools.com/docs/handbook-layouts-wizard-pivot/index.md) for full instructions on configuring Layouts at runtime

## UI Entitlements

The [UI Entitlements](https://www.adaptabletools.com/docs/handbook-permissioning/index.md) behaviour for Layouts is slightly more complicated than for other Modules, because Layouts are intrinsic to how AdapTable works. The rules are as follows:

- `Full` Entitlement - everything works as expected and nothing is hidden or disabled.

- `ReadOnly` Entitlement - existing Layouts can be selected, but Users cannot add, clone or delete them, nor edit them in Layout Wizard

- Layouts are modifiable at run-time by users resizing / moving Columns in the UI or AG Grid Columns ToolPanel
- However changes made to the Layout will not be persisted into State (nor available when the app next loads)

It is possible to prevent any changes to the Layout but not by using Entitlements, but instead to:

- Either set up strict, initial Column Schema definitions in GridOptions that prevent undesired modifications
- Or mark the Layout with `ReadOnly` set to _true_ and AdapTable will prevent any changes as much as possible

- `Hidden` Entitlement - Layouts - and all Layout-related UI controls - are hidden from the User.

- You still need to ensure that at least one Layout is defined (though the Layout UI controls will be invisible to the User)
- AdapTable will update and persist the Layout as AG Grid changes, and re-load it on application re-start

### Read-Only Layouts

Like all [Adaptable Objects](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-initial-state/index.md#adaptable-objects), Layouts can be set with `ReadOnly` as true.

However, given the nature of Layouts this is more limited than with other objects.

## Advanced Layouts

There are many advanced use cases regarding Layouts which AdapTable supports. These include:

- [Default Layouts](https://www.adaptabletools.com/docs/handbook-layouts-default/index.md)
- [Programmatically Updating Layouts](https://www.adaptabletools.com/docs/handbook-layouts-updating/index.md)
- [Synchronising Layouts](https://www.adaptabletools.com/docs/handbook-layouts-synchronising/index.md)
- [Configuring Layouts](https://www.adaptabletools.com/docs/handbook-layouts-configuring/index.md)

## Logging Layout Changes

AdapTable provides additional and specific logging capability for Layouts.

This logs to the console details of all changes to any Layout.

See [Logging Layout Details](https://www.adaptabletools.com/docs/dev-guide-support-logging/index.md#layout-logging) for full details

### FAQ

**Is there a limit on the number of Layouts allowed?**
No, you can create as many Layouts as you wish but you must always have at least one Layout.
AdapTable will prevent you from deleting the last Layout in your state.

**Can my colleague use the same Layout as me?**
Yes, if [Team Sharing](https://www.adaptabletools.com/docs/handbook-team-sharing/index.md) is enabled, then you can upload your Layout so that your colleague can also access it.

**Does a Layout include which column(s) is currently sorted?**
Yes.

**Does a Layout include pivoting?**
Yes.

**Can a Layout include multiple sorts?**
Yes.

**Does a Layout include information about column widths or pinning?**
Yes it can - and it will be updated and saved automatically as the Layout changes.

**Why do I not see all my Columns in the Aggregations or Grouping steps in the Layout Wizard?**
AdapTable follows the same rules as AG Grid for what can be set in the UI.
This is based on the properties that have been set in the Column's definition in AG Grid GridOptions:

- The `Row Groups` step lists all Columns it defines as Groupable - where `enableRowGroup` is set to _true_
- The `Aggregations` step lists all Columns it defines as Aggregatable - where `enableValue` is set to _true_

**Is every Layout editable and deletable?**
Yes, assuming that your [Entitlements](https://www.adaptabletools.com/docs/handbook-permissioning/index.md) `AccessLevel` property for Layouts is Full.

**Can I include Format Columns, Alerts and other elements in my Layout?**
Not directly, because a Layout only includes Column-related information.
Use [Layout Extensions](https://www.adaptabletools.com/docs/handbook-layouts-extending/index.md) to limit Format Columns, Styled Columns, Alerts, Custom Sorts, Flashing Cells, Plus Minus Nudges or Shortcuts to specific Layouts. Reports cannot be extended into a Layout.

**Why do the Columns in my Layout "jump back" after I move them?**
Check that the Layout is not set to `ReadOnly`; if it is, AdapTable tries to prevent any changes to the Layout.
