# Defining Columns

The [Angular TreeList](https://www.telerik.com/kendo-angular-ui/components/treelist) enables you to define its columns in two ways. You can either:

* [Define the columns explicitly in the component template](https://www.telerik.com/kendo-angular-ui/components/treelist/columns/define-columns#using-the-column-component).
* [Let the TreeList generate the columns automatically based on the provided data](https://www.telerik.com/kendo-angular-ui/components/treelist/columns/define-columns#automatic-column-generation).

## Using the Column Component

To define the TreeList columns in a declarative way, nest the columns as tags inside the `<kendo-treelist>` tag. This approach is convenient for configuring the columns and enabling various features like [`hidden`](https://www.telerik.com/kendo-angular-ui/components/treelist/columns/hidden) and [`locked`](https://www.telerik.com/kendo-angular-ui/components/treelist/columns/locked) states, [`resizing`](https://www.telerik.com/kendo-angular-ui/components/treelist/columns/resizing), [`reordering`](https://www.telerik.com/kendo-angular-ui/components/treelist/columns/reordering), and many more.

The available column components provided by the TreeList are:

* [`<kendo-treelist-column>`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columncomponent)—Represents the basic TreeList column. Used to display model data or templated content.
* [`<kendo-treelist-column-group>`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/columngroupcomponent)—Used to define multi-column group headers, which span over subordinate columns.
* [`<kendo-treelist-checkbox-column>`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/checkboxcolumncomponent)—Defines a column with a dedicated checkbox for row selection.
* [`<kendo-treelist-command-column>`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/commandcolumncomponent)—Defines a column dedicated to displaying command buttons like **Edit**, **Remove**, and others.
* [`<kendo-treelist-span-column>`](https://www.telerik.com/kendo-angular-ui/components/treelist/api/spancolumncomponent)—Enables you to span row content over multiple cells while retaining the individual header and footer cells.

The following code snippet will produce a TreeList with two columns bound to the `name` and `title` fields of the model:

```html
<kendo-treelist [kendoTreeListFlatBinding]="data" ...>
    <kendo-treelist-column field="name" title="Name"> </kendo-treelist-column>
    <kendo-treelist-column field="title" title="Title"> </kendo-treelist-column>
<kendo-treelist>
```

The code above demonstrates how to configure the following column properties:

* `field`—The model field to which you bind the column.
* `title`—The column header text. If you don't provide it, the TreeList displays the `field` property name in the header.

The example below demonstrates how to define the TreeList columns in the template.

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

### Dynamic Column Generation

The TreeList enables you to generate columns based on a configuration array. This dynamic column generation approach is convenient for a few scenarios:

* The number of columns that must be displayed is large and you don't want to manually list all of them in the TreeList template.
* The column number and configuration will vary based on some business logic.
* The column configuration must be stored and loaded separately, for example, from a remote service.

To configure dynamic column generation, use the Angular [`@for`](https://angular.dev/api/core/@for#) block template syntax to loop through a column configuration array. The columns will be rendered according to the items order in the passed collection.

```html
<kendo-treelist [kendoTreeListFlatBinding]="data" ...>
    @for (column of columnsConfig; track column.field) {
        <kendo-treelist-column 
            field="{{ column.field }}"
            title="{{ column.title }}"
            [expandable]="column.expandable">
        </kendo-treelist-column>
    }
</kendo-treelist>
```

The following example demonstrates how to generate the TreeList columns by using the `@for` block template syntax.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/columns/ng-for/source.txt)

## Automatic Column Generation

By default, if the columns are not explicitly configured, the TreeList will generate a column for each model field from the bound data. For example, when bound to the data below, the TreeList will generate five columns (`Id`, `ParentId`, `Name`, `Role`, and `Phone`):

```ts
public data = medicalStaff.map(({ id, parentId, name, role, phone }) => ({
    id, parentId, name, role, phone
}));
```

The following example demonstrates the TreeList default column generation.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/columns/default-config/source.txt)

## Suggested Links

* [`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)
* [Angular `@for` block template syntax](https://angular.dev/api/core/@for#)
