# Hiding Columns

Canonical page: https://www.adaptabletools.com/docs/dev-guide-columns-hiding-columns

- AdapTable allows Columns to be defined as Hidden, by setting a type of `hiddenColumn` in ColDefs
- Hidden Columns are never visible in the Grid (or the AdapTable UI) but can be used in Expressions

Columns can be hidden in AdapTable so that they are never displayed in the UI.

This is especially useful if you are using a primary key column which you do not want users to see or edit.

- A hidden Column will still be listed in the Columns section of the [Expression Editor](https://www.adaptabletools.com/docs/ui-expression-editor/index.md) and in the [Query Builder](https://www.adaptabletools.com/docs/ui-query-builder/index.md)
- This allows it to form part of an Expression (e.g. to be used in [Calculated Columns](https://www.adaptabletools.com/docs/handbook-calculated-column/index.md) or the [Grid Filter](https://www.adaptabletools.com/docs/handbook-grid-filter/index.md))

This is done by setting (or adding) `hiddenColumn` to the `type` property in the AG Grid ColDef definition.

- Alternatively you can use the `AdaptableColumnType.HiddenColumn` constant
- See the [Guide to Providing Column Types](https://www.adaptabletools.com/docs/dev-guide-columns-column-types/index.md) for more information of setting column types

```ts {6,11}
// Add 2 hidden columns
export const columnDefs: ColDef<WebFramework>[] = [
  {
    field: 'id',
    cellDataType: 'number',
    type: 'hiddenColumn',
  },
  {
    field: 'map',
    cellDataType: 'text',
    type: AdaptableColumnType.HiddenColumn,
  },
]
```

- AG Grid offers a similar ColDef property named `hide` which if set to *true* will hide the Column
- AdapTable [ignores this property](https://www.adaptabletools.com/docs/dev-guide-columns-configuring-coldefs/index.md) and sets visibility based purely on [Layout properties](https://www.adaptabletools.com/docs/handbook-layouts-table-column-visibility/index.md) and the `hiddenColumn` type

**Example: Hiding a Column in AdapTable UI**

Hide a column so its never visible to a user

- In this example we "hide" the `Github Watchers` and `Github Stars` Columns by setting their ColDef `type` property to *HiddenColumn*
- As a result they are not visible in the Grid, nor in the `Columns` [Tool Panel](https://www.adaptabletools.com/docs/ui-tool-panel/index.md) and nor the Layout Wizard
- However they are still available for use in [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)

- Open Columns [Tool Panel](https://www.adaptabletools.com/docs/ui-tool-panel/index.md) and note the `Github Watchers` and `Github Stars` Columns are not listed (but the Calculated Column `Github Total` is listed)
- Edit the [Grid Filter](https://www.adaptabletools.com/docs/handbook-grid-filter/index.md), or the `Github Total` [Calculated Column](https://www.adaptabletools.com/docs/handbook-calculated-column/index.md), and note `Github Watchers` & `Github Stars` Columns are referenced in the Expression and available in [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)
- Note also that we set the `Name` column with *hide* in ColDefs but that gets ignored by AdapTable and the column is displayed (as its in the Layout)

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

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts
  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: 'Hiding A Column',
  initialState: {
    Theme: {CurrentTheme: 'dark'},
    Dashboard: {
      ModuleButtons: ['CalculatedColumn'],
      PinnedToolbars: ['GridFilter'],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'helll',
            'name',
            'language',
            'license',
            'github_stars',
            'github_total',
            'open_issues_count',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'closed_issues_count',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
            'week_issue_change',
          ],
          GridFilter: {
            Expression: '[github_watchers] > 20500 OR [github_stars] > 8500',
          },
          AutoSizeColumns: true,
        },
      ],
    },
    CalculatedColumn: {
      CalculatedColumns: [
        {
          ColumnId: 'github_total',
          FriendlyName: 'Github Total',
          Expression: '[github_watchers] + [github_stars]',
          CalculatedColumnSettings: {
            DataType: 'number',
            Resizable: true,
            Width: 200,
          },
        },
      ],
    },
  },
};
```
**`src/columnDefs.ts`**

```ts
import {AdaptableColumnType} from '@adaptabletools/adaptable';
import {ColDef} from 'ag-grid-enterprise';
import {WebFramework} from './rowData';

export const columnDefs: ColDef<WebFramework>[] = [
  {
    field: 'id',
    cellDataType: 'number',
    editable: false,
  },
  {
    field: 'github_watchers',
    headerName: 'GitHub Watchers',
    cellDataType: 'number',
    type: AdaptableColumnType.HiddenColumn,
  },
  {
    field: 'name',
    cellDataType: 'text',
    sortable: true,
    hide: true, // this is ignored by AdapTable
  },
  {
    field: 'language',
    cellDataType: 'text',
    enablePivot: true,
    enableRowGroup: true,
  },
  {
    field: 'github_stars',
    headerName: 'GitHub Stars',
    cellDataType: 'number',
    enableValue: true,
    type: AdaptableColumnType.HiddenColumn,
  },
  {
    field: 'license',
    cellDataType: 'text',
    editable: false,
    enablePivot: true,
    enableRowGroup: true,
  },
  {
    field: 'week_issue_change',
    headerName: 'Issue Change',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'created_at',
    headerName: 'Created',
    cellDataType: 'date',
  },
  {
    field: 'has_wiki',
    headerName: 'Has Wiki',
    cellDataType: 'boolean',
    enablePivot: true,
    enableRowGroup: true,
  },
  {
    field: 'updated_at',
    headerName: 'Updated',
    cellDataType: 'date',
  },
  {
    field: 'pushed_at',
    headerName: 'Pushed',
    cellDataType: 'date',
  },

  {
    field: 'description',
    cellDataType: 'text',
    sortable: false,
  },
  {
    field: 'open_issues_count',
    headerName: 'Open Issues',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'closed_issues_count',
    headerName: 'Closed Issues',
    cellDataType: 'number',
    enableValue: true,
  },

  {
    field: 'open_pr_count',
    headerName: 'Open PRs',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'closed_pr_count',
    headerName: 'Closed PRs',
    cellDataType: 'number',
    enableValue: true,
  },
  {field: 'has_projects', headerName: 'Has Projects', cellDataType: 'boolean'},
  {field: 'has_pages', headerName: 'Has Pages', cellDataType: 'boolean'},
  {
    field: 'topics',
    cellDataType: 'textArray',
    editable: false,
    sortable: false,
  },
];
```
