# Angular TreeList Column Menu

The [Angular TreeList](https://www.telerik.com/kendo-angular-ui/components/treelist) allows you to show a menu with quick actions for its columns.

The column menu provides a convenient way to apply data processing features to the specified columns. The user can sort and filter the TreeList data, toggle the locked state of the columns, or change their visibility. You can customize the order of the menu items and create custom controls as necessary.

To display the column menu on each column, set the [`columnMenu`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent#columnmenu) option of the TreeList. The property accepts both `boolean` and [`ColumnMenuSettings`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenusettings) parameters. The default value of the `columnMenu` option is `false`.

The following example demonstrates a basic column menu in action.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/column-menu/basic/source.txt)

## Configuring the Column Menu

To specify which items to appear in the column menu, pass a [`ColumnMenuSettings`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenusettings) parameter object to the [`columnMenu`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent#columnmenu) option.

The available predefined column menu items are:

* [Sort item](https://www.telerik.com/kendo-angular-ui/components/treelist/accessories/column-menu#sort-item)—Displays **Sort Ascending** and **Sort Descending** buttons, which apply the corresponding sorting to the current column. If the TreeList is [`sortable`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent#sortable), this option defaults to `true` for model-bound columns.
* [Filter item](https://www.telerik.com/kendo-angular-ui/components/treelist/accessories/column-menu#filter-item)—Displays a **Filter** button and an expandable filter menu. If the TreeList is [`filterable`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent#filterable), this option defaults to `true` for model-bound columns.
* [Lock and unlock items](https://www.telerik.com/kendo-angular-ui/components/treelist/accessories/column-menu#lock-and-unlock-items)—Determines if the users can lock and unlock the column through the column menu. Defaults to `false`.
* [Column Chooser item](https://www.telerik.com/kendo-angular-ui/components/treelist/accessories/column-menu#column-chooser-item)—Displays a **Columns** button and an expandable checkbox-style menu with all columns. This menu allows users to quickly show or hide TreeList columns. Defaults to `true`.

### Sort Item

The sort item of the column menu is displayed by default if the following conditions are met:

* The [`sortable`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent#sortable) functionality of the TreeList is enabled.
* The current column binds to a field from the TreeList model.

To add the sort item without enabling sorting, manually set the [`sort`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenusettings#sort) option of the `ColumnMenuSettings` to `true`. To hide the sort item for individual columns, set the [`sortable`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columncomponent#sortable) option of the column to `false`.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/column-menu/sort/source.txt)

### Filter Item

The filter item of the column menu is displayed by default if the following conditions are met:

* The [`filterable`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent#filterable) functionality of the TreeList is enabled.
* The current column binds to a field from the TreeList model.

To add the filter item without enabling filtering, set the [`filter`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenusettings#filter) option of the `ColumnMenuSettings` to `true`. To hide the filter item for individual columns, set the [`filterable`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columncomponent#filterable) option of the column to `false`.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/column-menu/filter/source.txt)

### Lock and Unlock Items

The lock and unlock items of the column menu are not displayed by default. To add them, set the [`lock`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenusettings#lock) option of the `ColumnMenuSettings` to `true`. To hide the lock and unlock items for individual columns, set the [`lockable`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columncomponent#lockable) option of the corresponding column to `false`.

> The prerequisites and limitations of the [locked columns](https://www.telerik.com/kendo-angular-ui/components/treelist/columns/locked) apply to the lock item.

The following example demonstrates how to lock and unlock columns from the column menu.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/column-menu/lock/source.txt)

### Column Chooser Item

The column chooser item allows you to dynamically show and hide columns through a dedicated sub-menu with checkboxes. The column menu displays a column chooser item by default. To hide it, set the [`columnChooser`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenusettings#columnChooser) option of the `ColumnMenuSettings` to `false`.

The following example demonstrates the column chooser item.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/column-menu/chooser/source.txt)

To exclude a column from the column chooser checkbox list, set the [`includeInChooser`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columncomponent#includeinchooser) property of the respective column to `false`.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/column-menu/chooser-exclude/source.txt)

### AutoSize-Column Item

The autosize-column item allows you to resize the column to the minimum possible width so that it fits the widest header or cell content without wrapping. The option is hidden by default. To display it you must set the following options:

1. [`resizable`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent#resizable) property of the TreeList to `true`.
2. [`autoSizeColumn`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenusettings#autosizecolumn) option of the `ColumnMenuSettings` to `true`.

> Using autosize-column item option alongside the [virtual columns](https://www.telerik.com/kendo-angular-ui/components/treelist/columns/virtual) functionality is not supported.

The following example demonstrates how to add the autosize-column item to the column menu.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/column-menu/autosize-column/source.txt)

### AutoSize-All-Columns Item

The autosize-all-columns item allows you to resize all columns to the minimum possible width so that they fit the widest header or cell content without wrapping. The option is hidden by default. To display it you must set the following options:

1. [`resizable`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent#resizable) property of the TreeList to `true`.
2. [`autoSizeAllColumns`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenusettings#autosizeallcolumns) option of the `ColumnMenuSettings` to `true`.

> Using autosize-all-columns item option alongside the [virtual columns](https://www.telerik.com/kendo-angular-ui/components/treelist/columns/virtual) functionality is not supported.

The following example demonstrates how to add the autosize-all-columns item to the column menu.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/column-menu/autosize-all-columns/source.txt)

### Expandable Menu Items

By default, the column chooser and filter column menu items are initially collapsed. To change this behavior and make them initially expanded, set the [`expanded`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/expandablecolumnmenuitem) property of the [`ExpandableColumnMenuItem`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/expandablecolumnmenuitem) object to `true`.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/column-menu/expandable-menu/source.txt)

## Customizing the Content

You can customize the content of the column menu through templates. This approach allows you to specify a column menu template for:

* All Columns—Nest an `<ng-template>` tag with the [`kendoTreeListColumnMenuTemplate`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenutemplatedirective) directive inside the `kendo-treelist` component.
* Specific Column—Nest the template inside the column component tag, for example, inside `kendo-treelist-column`.

> Before using the predefined column menu items inside the template, set the [`ColumnMenuService`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenuservice) that is passed by the template to the `service` input of the column menu item.

To include the predefined column menu items in the template, add the following components:

* [`kendo-treelist-columnmenu-sort`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenusortcomponent)
* [`kendo-treelist-columnmenu-filter`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenufiltercomponent)
* [`kendo-treelist-columnmenu-lock`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenulockcomponent)
* [`kendo-treelist-columnmenu-chooser`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenuchoosercomponent)
* [`kendo-treelist-columnmenu-autosize-column`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenuautosizecolumncomponent)
* [`kendo-treelist-columnmenu-autosize-all-columns`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenuautosizeallcolumnscomponent)

To implement an entirely custom column menu item and include it in the template, use the [`kendo-treelist-columnmenu-item`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenuitemcomponent) component.

To enable the built-in keyboard navigation for column menu items used inside the template, set the [`kendoTreeListColumnMenuItem`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenuitemdirective) directive to the reference of the component:

```html
<ng-template kendoTreeListColumnMenuTemplate let-service="service" let-column="column">
    <kendo-treelist-columnmenu-sort #sortItem [kendoTreeListColumnMenuItem]="sortItem" [service]="service">
    </kendo-treelist-columnmenu-sort>
</ng-template>
```

The following example demonstrates how to define a custom column menu template.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/column-menu/template/source.txt)

## Customizing the Position

By default, the column menu renders as the last item in the header cell. To change the position of the menu icon in the header, follow the steps below:

1. Disable the built-in column menu by setting [`columnMenu`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columncomponent#columnmenu) on the respective column to `false`.
2. Nest an `<ng-template>` tag inside the column and apply a [`HeaderTemplateDirective`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/headertemplatedirective) directive to it.
3. Place a [`ColumnMenu`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenucomponent) component anywhere in the header template by nesting a `<kendo-treelist-column-menu>` tag inside.
4. Bind the `column` property of the [`ColumnMenu`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenucomponent) component to the `column` field that is passed by the template.
5. Optionally, bind the `sort` and `filter` properties of the [`ColumnMenu`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenucomponent) component to the respective TreeList state.

> When used as a standalone component, the [`ColumnMenu`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnmenucomponent) ignores the [sortable](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent#sortable) and [filterable](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent#filterable) settings of the TreeList. You must configure the respective column menu items through the component properties instead.

The following example demonstrates the described approach for changing the column menu position inside the cell header template.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/column-menu/standalone/source.txt)

## Hiding the Column Menu per Column

By default, the column menu appears for all columns. To disable the column menu for specific columns, use the [`columnMenu`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columncomponent#columnmenu) option of the respective column and set it to `false`.

The following example demonstrates a TreeList where the column menu is hidden for the first (**Name**) column. The column menu icon is visible only on the remaining columns.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/column-menu/disable/source.txt)

## Using a Standalone Column Chooser

You can use the column chooser item outside the column menu.

To allow the user to show and hide the columns without including the column chooser item in the column menu, use the [`ColumnChooser`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columnchoosercomponent) component separately by nesting a `<kendo-treelist-column-chooser>` tag inside the [`TreeList toolbar`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/toolbartemplatedirective).

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/column-menu/chooser-toolbar/source.txt)

## Suggested Links

* [API Reference of the ColumnComponent](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columncomponent)
* [API Reference of the TreeListComponent](https://www.telerik.com/kendo-angular-ui/components/treelist/api/treelistcomponent)
* [API Index of the TreeList](https://www.telerik.com/kendo-angular-ui/components/treelist/api)
