# Table Layouts - Column Visibility

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

- The Table Layout supports customising Column Visibility

[Layouts](https://www.adaptabletools.com/docs/handbook-layouts/index.md) · [Table Layouts](https://www.adaptabletools.com/docs/handbook-layouts-table/index.md) · [All Table Layout Topics](https://www.adaptabletools.com/docs/handbook-layouts-table/index.md#table-layout-topics)

Any Column that is listed in the `TableColumns` property in the Layout will be visible in the Grid.

This means that if you wish for a Column not to be visible, simply don't include it in this array.

The Column will still be available in the Columns Tool Panel, so that it can be made visible in the Grid.

However it is possible to specify explicitly that a Column not be visible by adding it to the Layout's `ColumnVisibility` property.

## Position

The main advantage to explicitly setting column invisibility, is position.

In other words you can set where non-visible columns will appear in the Columns Tool Panel (and, consequently, their position in the Grid when made visible).

Configuring the position of non-visible Columns is done using 2 properties in the Layout:
- listing the Column (in its preferred position) in `TableColumns` property
- adding the Column to the `ColumnVisibility` property

AdapTable automatically updates this property each time a Column is made invisible via the UI.

### Setting Column Visibility

By default every Column listed in `TableColumns` property is visible in the Grid.

`ColumnVisibility` will make some columns hidden at start-up.

This allows you to "position" the invisible column in the correct place should the user later make it visible in the UI.

```ts [[1, 10, "ColumnVisibility"]]
// Make license and name Columns invisible
// They will not be visible but their order in the Columns array is maintained
const initialState: InitialState = {
 Layout: {
  CurrentLayout: 'Column Visibility Layout',
  Layouts: [
  {
    Name: 'Column Visibility Layout',
    TableColumns: ['license', 'github_watchers', 'name', 'github_stars', 'language', 'open_pr_count'],
    ColumnVisibility: {
      license: false,
      name: false,
    },
  }]
 },
};
```

**Example: Table Layouts: Column Visibility**

Creating Table Layouts with custom Column Visibility

- This example also sets 2 columns (*License* and *Github Stars*) to be invisible using 2 Layouts:
  -  `Column Visibility 1` positions them at the top of TableColumns
  -  `Column Visibility 2` lists them further down in TableColumns
- In both Layouts checking either of these Columns will make them visible - in the position they were listed in Table Columns

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
  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: 'Table Layouts Column Visibility',
  initialState: {
    Dashboard: {
      ModuleButtons: ['Layout'],
      Tabs: [
        {
          Name: 'Default',
          Toolbars: ['Layout', 'GridFilter'],
        },
      ],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Layout'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},

    Layout: {
      CurrentLayout: 'Column Visibility 1',
      Layouts: [
        {
          TableColumns: [
            'github_stars',
            'license',
            'name',
            'language',
            '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 1',
          AutoSizeColumns: true,
        },
        {
          TableColumns: [
            'name',
            'language',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'github_stars',
            'license',
            '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 2',
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```
**`src/onAdaptableReady.ts`**

```ts
import {AdaptableReadyInfo} from '@adaptabletools/adaptable';

export const onAdaptableReady = (info: AdaptableReadyInfo) => {
  info.agGridApi.openToolPanel('columns');
};
```

## Always Hidden Columns

AdapTable allows for developers to set a Column to be [always hidden in the UI](https://www.adaptabletools.com/docs/dev-guide-columns-hiding-columns/index.md), by leveraging [Column Types](https://www.adaptabletools.com/docs/dev-guide-columns-column-types/index.md).

See [Hiding Columns in AdapTable](https://www.adaptabletools.com/docs/dev-guide-columns-hiding-columns/index.md) for more details on how to achieve this, together with a demo

When a Column is set to be always hidden, it will not be:
- rendered in the Grid
- available in the Layout Wizard Editor
- listed in the Columns Tool Panel

- Hiding Columns in this way takes precedence over properties in a Layout (and in ColDefs)
- Even if the Column is listed in `TableColumns`, it will still not be rendered if it has a type of `hiddenColumn`

- However, it is a "real" Column and therefore still available in Expressions, e.g. in [Calculated Columns](https://www.adaptabletools.com/docs/handbook-calculated-column/index.md) or [Grid Filter](https://www.adaptabletools.com/docs/handbook-grid-filter/index.md)
- It is also available in the [Expression Editor](https://www.adaptabletools.com/docs/ui-expression-editor/index.md) and [Query Builder](https://www.adaptabletools.com/docs/ui-query-builder/index.md) in order to use it to create these Expressions

## ColDef `hide` property

The AG Grid Column Definition has a `hide` property which ensures a column is not rendered.

This property is ignored by AdapTable which uses the rules described above for setting column visibility.
