# Table Layouts

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

- Table Layouts manage Column-related info when the Grid is in standard (ie. non Pivot) mode
- They can be created / edited at run-time through the Layout Wizard or configured at design-time

Concepts shared with all layouts — [Layouts](https://www.adaptabletools.com/docs/handbook-layouts/index.md). Pivot mode — [Pivot Layouts](https://www.adaptabletools.com/docs/handbook-layouts-pivot/index.md).

## Table Layout Topics

| Topic | Summary |
| ----- | ------- |
| [Column Order](https://www.adaptabletools.com/docs/handbook-layouts-table-column-order/index.md) | Column sequence in the layout |
| [Column Visibility](https://www.adaptabletools.com/docs/handbook-layouts-table-column-visibility/index.md) | Which columns are shown or hidden |
| [Column Sizing](https://www.adaptabletools.com/docs/handbook-layouts-table-column-sizing/index.md) | Widths and auto-size behaviour |
| [Column Pinning](https://www.adaptabletools.com/docs/handbook-layouts-table-pinning/index.md) | Left and right pinned columns |
| [Sorting](https://www.adaptabletools.com/docs/handbook-layouts-table-sorting/index.md) | Layout-managed column sorts |
| [Column Headers](https://www.adaptabletools.com/docs/handbook-layouts-table-column-headers/index.md) | Header display names in the layout |
| [Other Table Layout Properties](https://www.adaptabletools.com/docs/handbook-layouts-table-grouping-filtering/index.md) | Row groups, aggregations, column and grid filters |
| [Row Selection](https://www.adaptabletools.com/docs/handbook-layouts-table-row-selection/index.md) | Selection mode and checkboxes saved in the layout |
| [Table Layout Wizard](https://www.adaptabletools.com/docs/handbook-layouts-wizard-table/index.md) | Run-time wizard steps |

Table Layouts show AG Grid columns in standard (i.e. non pivot) form.  

Table Layouts can be provided, and configured, in AdapTable in 3 ways:
- at design time using [Initial Adaptable State](https://www.adaptabletools.com/docs/technical-reference-layouts/index.md)
- at run time through the [Table Layout UI Wizard](https://www.adaptabletools.com/docs/handbook-layouts-wizard-table/index.md)  
- programmatically via the [Layout API](https://www.adaptabletools.com/docs/technical-reference-layouts/index.md)

**Example: Table Layouts**

Creating Table Layouts

- This example contains 10 Table Layouts (each showing a different aspect of Layouts - many of which are explained more fully in other pages in this section):
  - `Sorted Layout` (the Current Layout by default) with sorting on 2 columns: `Licence` (ASC and also using a [Custom Sort](https://www.adaptabletools.com/docs/handbook-custom-sorting/index.md)) and *Name* (DESC)
  - `Custom Header Names` where 2 columns have been renamed: *Name* is now 'Project', and *Language* is 'Programming Language'
  - `Custom Column Widths` where the *Name*, *Language* and *Topics* columns have all been given bespoke widths
  - `Pinned Columns` which has pinned the *Name* and *Language* columns to the *left* and `Github Watchers` column to the *right*
  - `Grouping` which has row-grouped AG Grid on the *Language* and then *License* columns
  - `Aggregation` - Language column is row-grouped and aggregations have been set for *Open Issues* (sum) & *Closed Issues* (max) columns
  - `Filter` - A [Grid Filter](https://www.adaptabletools.com/docs/handbook-grid-filter/index.md) has been applied together with 4 [Column Filters](https://www.adaptabletools.com/docs/handbook-column-filter/index.md)
  - `Summary` - A [Row Summary](https://www.adaptabletools.com/docs/handbook-summarising-rows/index.md) at Top of Grid shows Aggregations for *Language*, *Issue Change*, *Github Stars*, *Github Watchers* Columns
  - `Special Cols` - contains 3 Special Columns: [Calculated Column](https://www.adaptabletools.com/docs/handbook-calculated-column/index.md) (`Total PRs`), [FreeText Column](https://www.adaptabletools.com/docs/handbook-freetext-column/index.md)(`Comments`) and an [Action Column](https://www.adaptabletools.com/docs/handbook-action-column/index.md) (`Add Star`)
  - `Column Visibility` - sets 2 columns (*License* and *Github Stars*) to be invisible (but by listing them in Columns they are correctly placed when made visible)
 
Select different Layouts and see how the AG Grid columns are displayed differently

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 {
  ActionColumnContext,
  AdaptableOptions,
  CellUpdateRequest,
} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Table Layouts',
  actionColumnOptions: {
    actionColumns: [
      {
        columnId: 'add_star',
        friendlyName: 'Add Star',
        settings: {
          suppressMenu: true,
          resizable: false,
        },
        controls: [
          {
            type: 'button',
            label: 'Add Star',
            style: {variant: 'raised', tone: 'accent'},
            onClick: (context: ActionColumnContext) => {
              const rowData: any = context.rowNode?.data;
              const cellUpdateRequest: CellUpdateRequest = {
                columnId: 'github_stars',
                newValue: rowData.github_stars + 1,
                primaryKeyValue: context.primaryKeyValue,
                rowNode: context.rowNode,
              };
              context.adaptableApi.gridApi.setCellValue(cellUpdateRequest);
            },
          },
        ],
      },
    ],
  },
  initialState: {
    Dashboard: {
      ModuleButtons: ['Layout'],
      Tabs: [
        {
          Name: 'Default',
          Toolbars: ['Layout', 'GridFilter'],
        },
      ],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Layout'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    CustomSort: {
      CustomSorts: [
        {
          Name: 'customSort-license',
          ColumnId: 'license',
          SortedValues: ['Other'],
        },
      ],
    },
    Layout: {
      CurrentLayout: 'Sorted',
      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: 'Sorted',
          ColumnSorts: [
            {
              ColumnId: 'license',
              SortOrder: 'Asc',
            },
            {
              ColumnId: 'name',
              SortOrder: 'Desc',
            },
          ],
          AutoSizeColumns: true,
        },
        {
          ColumnHeaders: {
            name: 'Project',
            language: 'Programming Language',
          },
          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',
          ],
          //  AutoSizeColumns: true,
          Name: 'Custom Header Names',
        },
        {
          TableColumns: ['name', 'language', 'github_stars', 'topics'],
          Name: 'Custom Column Widths',
          ColumnSizing: {
            name: {Width: 100},
            language: {Width: 118},
            topics: {Width: 700},
          },
        },
        {
          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: 'Pinned Columns',
          ColumnPinning: {
            name: 'left',
            language: 'left',
            github_watchers: 'right',
          },
          AutoSizeColumns: true,
        },
        {
          TableColumns: [
            'name',
            'github_stars',
            '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: 'Grouping',
          RowGroupedColumns: ['language', 'license'],
          AutoSizeColumns: true,
        },
        {
          TableColumns: [
            'name',
            'language',
            'open_issues_count',
            'closed_issues_count',
          ],
          Name: 'Aggregation',
          RowGroupedColumns: ['language'],
          TableAggregationColumns: [
            {
              ColumnId: 'closed_issues_count',
              AggFunc: 'max',
            },
            {
              ColumnId: 'open_issues_count',
              AggFunc: 'sum',
            },
          ],
          AutoSizeColumns: true,
        },
        {
          Name: 'Filter',
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'github_watchers',
            'license',
            'pushed_at',
            'updated_at',
            'has_wiki',
            'created_at',
            'description',
            'open_issues_count',
          ],
          GridFilter: {
            Expression: '[license]="MIT License" OR [github_watchers] > 2000',
          },
          ColumnFilters: [
            {
              ColumnId: 'language',
              Expression: '[language] = "TypeScript" OR [language] = "JavaScript"',
            },
            {
              ColumnId: 'github_stars',
              Expression: '[github_stars] > 5000 AND [github_stars] < 90000',
            
            },
            {
              ColumnId: 'name',
              Expression: 'name.endsWith(".js")',
            },
            {
              ColumnId: 'pushed_at',
              Expression: '[pushed_at] > DATE("2016-01-01")',
          
            },
          ],
          AutoSizeColumns: true,
        },
        {
          TableColumns: [
            'name',
            'language',
            'week_issue_change',
            'github_stars',
            'github_watchers',
            'license',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'open_issues_count',
            'closed_issues_count',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
          ],
          RowSummaries: [
            {
              Position: 'Top',
              ColumnsMap: {
                github_watchers: 'SUM',
                github_stars: 'SUM',
                week_issue_change: 'AVG',
                language: 'COUNT',
              },
            },
          ],
          Name: 'Summary',
          AutoSizeColumns: true,
        },
        {
          TableColumns: [
            'name',
            'comments',
            'github_stars',
            'add_star',
            'total_pr_count',
            'open_pr_count',
            'closed_pr_count',
            'github_watchers',
            'license',
            'language',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'open_issues_count',
            'closed_issues_count',
          ],
          Name: 'Special Cols',
          AutoSizeColumns: true,
        },
        {
          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',
          ],
          ColumnVisibility: {
            license: false,
            github_stars: false,
          },
          Name: 'Column Visibility',
          AutoSizeColumns: true,
        },
      ],
    },
    CalculatedColumn: {
      CalculatedColumns: [
        {
          FriendlyName: 'Total PRs',
          ColumnId: 'total_pr_count',
          Expression: '[open_pr_count] + [closed_pr_count]',
          CalculatedColumnSettings: {
            DataType: 'number',
            Filterable: true,
          },
        },
      ],
    },
    FreeTextColumn: {
      FreeTextColumns: [
        {
          ColumnId: 'comments',
          FriendlyName: 'Comments',
          FreeTextStoredValues: [
            {PrimaryKey: 24195339, FreeText: 'Used by US team'},
            {PrimaryKey: 224663696, FreeText: 'My favourite'},
            {PrimaryKey: 82095231, FreeText: 'Required by Support'},
          ],
          FreeTextColumnSettings: {
            Resizable: true,
            DataType: 'text',
          },
        },
      ],
    },
  },
};
```

## Defining Table Layouts

When providing a Layout in Initial Adaptable State every property can be supplied if required.

There are many different properties that can be included in a Layout definition.

- In this section we divide Layouts into many different types for convenience (e.g. Grouping, Filtered etc.)
- But, in practice, any Layout can include any combination of these properties as required

### Anatomy of an AdapTable Table Layout

#### Base Properties

[`TableLayout`](https://www.adaptabletools.com/docs/reference/tablelayout.md) object inherits from [`LayoutBase`](https://www.adaptabletools.com/docs/reference/layoutbase.md) (used also for Pivot Layouts) which contains these properties:

| Property | Type | Description |
| --- | --- | --- |
| [AutoSizeColumns](https://www.adaptabletools.com/docs/reference/layoutbase.md#autosizecolumns) | `boolean` | Whether Columns should autosize when Layout first loads |
| [ColumnFilters](https://www.adaptabletools.com/docs/reference/layoutbase.md#columnfilters) | [`ColumnFilter`](https://www.adaptabletools.com/docs/reference/columnfilter.md)`[]` | Collection of Column Filters to apply in Layout |
| [ColumnGroupValues](https://www.adaptabletools.com/docs/reference/layoutbase.md#columngroupvalues) | [`ColumnGroupValues`](https://www.adaptabletools.com/docs/reference/columngroupvalues.md) | Defines which Column Groups are expanded / collapsed |
| [ColumnHeaders](https://www.adaptabletools.com/docs/reference/layoutbase.md#columnheaders) | [`ColumnStringMap`](https://www.adaptabletools.com/docs/reference/columnstringmap.md) | Set of custom header names for some (or all) Columns |
| [ColumnPinning](https://www.adaptabletools.com/docs/reference/layoutbase.md#columnpinning) | [`ColumnDirectionMap`](https://www.adaptabletools.com/docs/reference/columndirectionmap.md) | Columns pinned to an edge. Each entry is a column id set to `'left'` or `'right'`. Columns absent from the map are not pinned. |
| [ColumnSizing](https://www.adaptabletools.com/docs/reference/layoutbase.md#columnsizing) | [`ColumnSizingMap`](https://www.adaptabletools.com/docs/reference/columnsizingmap.md) | Controls size (width or flex &amp; min/max) for Columns |
| [ColumnSorts](https://www.adaptabletools.com/docs/reference/layoutbase.md#columnsorts) | [`ColumnSort`](https://www.adaptabletools.com/docs/reference/columnsort.md)`[]` | Sorting to apply in the Layout |
| [GrandTotalRow](https://www.adaptabletools.com/docs/reference/layoutbase.md#grandtotalrow) | `'top' \| 'bottom' \| 'pinnedTop' \| 'pinnedBottom' \| boolean` | Where the grand total row is shown.<br/><br/>`'top'`, `'bottom'`, `'pinnedTop'` or `'pinnedBottom'`. `true` is the same as `'top'`. `false`, or omitting the property, turns the grand total row off. |
| [GridFilter](https://www.adaptabletools.com/docs/reference/layoutbase.md#gridfilter) | [`GridFilter`](https://www.adaptabletools.com/docs/reference/gridfilter.md) | Grid Filter to apply in Layout |
| [Name](https://www.adaptabletools.com/docs/reference/layoutbase.md#name) | `string` | Name of the Layout as it appears in the Layout toolbar and tool panel |
| [OpenCharts](https://www.adaptabletools.com/docs/reference/layoutbase.md#opencharts) | [`LayoutOpenChart`](https://www.adaptabletools.com/docs/reference/layoutopenchart.md)`[]` | AG Grid charts to open when this layout is selected (by chart UUID or name) |
| [RowGroupDisplayType](https://www.adaptabletools.com/docs/reference/layoutbase.md#rowgroupdisplaytype) | `RowGroupDisplayType` | How Row Groups are displayed: &#39;single&#39; - one hierarchical group Column; &#39;multi&#39; - a separate group Column per Row Grouped Column; &#39;groupRows&#39; - full-width group rows (no group column); defaults to &#39;single&#39; |
| [RowGroupValues](https://www.adaptabletools.com/docs/reference/layoutbase.md#rowgroupvalues) | [`RowGroupValues`](https://www.adaptabletools.com/docs/reference/rowgroupvalues.md) | Defines which Row Groups are expanded / collapsed |
| [RowSelection](https://www.adaptabletools.com/docs/reference/layoutbase.md#rowselection) | [`LayoutRowSelection`](https://www.adaptabletools.com/docs/reference/layoutrowselection.md)` \| false` | Defines Row Selection behaviour for Layout; if false, Row Selection is disabled; if undefined, GridOptions is used |
| [SuppressAggFuncInHeader](https://www.adaptabletools.com/docs/reference/layoutbase.md#suppressaggfuncinheader) | `boolean` | Hides the aggFunc in Column header: e.g. &#39;sum(Price)&#39; becomes &#39;Price&#39; |
| [IsReadOnly](https://www.adaptabletools.com/docs/reference/layoutbase.md#isreadonly) | `boolean` | Sets Entity to ReadOnly (overwriting a Strategy Entitlement of &#39;Full&#39;) |

#### Table Properties

The [`TableLayout`](https://www.adaptabletools.com/docs/reference/tablelayout.md) object additionally contains these properties which are specific to Table Layouts:

| Property | Type | Description |
| --- | --- | --- |
| [ColumnVisibility](https://www.adaptabletools.com/docs/reference/tablelayout.md#columnvisibility) | [`ColumnBooleanFalseMap`](https://www.adaptabletools.com/docs/reference/columnbooleanfalsemap.md) | Columns to hide. Each entry is a column id set to `false`. Columns absent from the map stay visible. |
| [RowGroupedColumns](https://www.adaptabletools.com/docs/reference/tablelayout.md#rowgroupedcolumns) | `string[]` | Columns which are row-grouped when the Layout is applied |
| [RowSummaries](https://www.adaptabletools.com/docs/reference/tablelayout.md#rowsummaries) | [`RowSummary`](https://www.adaptabletools.com/docs/reference/rowsummary.md)`[]` | Pinned Rows that display Aggregation Info for a whole Column |
| [TableAggregationColumns](https://www.adaptabletools.com/docs/reference/tablelayout.md#tableaggregationcolumns) | [`TableAggregationColumns`](https://www.adaptabletools.com/docs/reference/tableaggregationcolumns.md) | Columns showing aggregated values in Grouped Rows; a record of ColumnId and aggfunc (e.g. sum) or &#39;true&#39; (to use default aggfunc) |
| [TableColumns](https://www.adaptabletools.com/docs/reference/tablelayout.md#tablecolumns) | `string[]` | Column ids in this layout, in display order. Required. |
| [IsReadOnly](https://www.adaptabletools.com/docs/reference/tablelayout.md#isreadonly) | `boolean` | Sets Entity to ReadOnly (overwriting a Strategy Entitlement of &#39;Full&#39;) |

## Table Layout UI Wizard

The [Layout Wizard](https://www.adaptabletools.com/docs/handbook-layouts-wizard-table/index.md) enables Table Layouts to be created and edited by run-time users.

It provides AdapTable users with a series of 8 steps to manage Table Layouts at run-time:

- General Settings - particularly Layout Name
- Columns - visibility, order, width, pinning and headers of Columns in the Layout can be set
- Row Groups - which columns are Row Grouped
- Aggregations - which columns will show aggregated info when in a Group Row
- Row Summaries - which [Row Summaries](https://www.adaptabletools.com/docs/handbook-summarising-rows/index.md) to display
- Sorting - what Column Sorts are applied
- Column Filters - sets the active Column Filters
- Grid Filter - applies a Grid Filter
- Summary - rich, visual summary of all settings applied in previous steps

See [Using the Layout UI Wizard](https://www.adaptabletools.com/docs/handbook-layouts-wizard-table/index.md) for more information
