# ToolBar

The [`ToolBar()`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/gridtoolbarcommandfactory) configuration option of the TreeList lets you add command buttons that allow the user to invoke built-in TreeList functionalities, such as adding data items, saving changes, searching, and so on.

You can also define and add [custom commands](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/treelist/toolbar#custom-commands) to the TreeList's ToolBar, further expanding its functionality. To customize the appearance of the ToolBar, you can [utilize templates](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/treelist/toolbar#toolbar-template-handler).

## Built-In Commands

You can configure the ToolBar and include any of the built-in commands:

```Razor HtmlHelper
.Toolbar(toolbar=> {
    toolbar.Columns();
        toolbar.Create();
        toolbar.Save();
    toolbar.Paste();
        toolbar.Pdf();
        toolbar.Excel();
        toolbar.Search();
    toolbar.Spacer();
    toolbar.Separator();
    })
```

| Command   | Description                                                                  | Resources                                                                                                                                              |
| --------- | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Columns   | Displays a global column menu.                                               | [Column menu documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/columns/column-menu#global-column-menu) |
| Create    | Adds an empty data item to the TreeList.                                     | [Editing functionality documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/editing/overview)             |
| Save      | Persists any data changes done by the end user.                              | [Editing functionality documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/editing/overview)             |
| Paste     | Enables the built-in paste operations.                                       | [Clipboard documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/clipboard)                                |
| Pdf       | Exports the TreeList data in PDF format.                                     | [PDF Export documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/export/pdf-export)                       |
| Excel     | Exports the TreeList data in MS Excel format.                                | [Excel Export documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/export/excel-export)                   |
| Search    | Adds the built-in search panel for the TreeList.                             | [Search Panel documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/search-panel)                          |
| Spacer    | Moves the tools that are declared after it to the right side of the ToolBar. | NA                                                                                                                                                     |
| Separator | Acts as a delimiter between the ToolBar Commands.                            | NA                                                                                                                                                     |

### Overflow

The built-in toolbar provides properties for customizing its overflow behavior and appearance.

The following example demonstrates how to modify the default overflow settings of the toolbar through the `Oveflow()` configuration.

```Razor
@(Html.Kendo().TreeList<Kendo.Mvc.Examples.Models.TreeList.EmployeeDirectoryModel>()
     .Name("treelist")
    .Toolbar(t => t.Items(item =>
     {
         item.Pdf();
         item.Search();
     })
     .Overflow(o => o
        .Mode(ToolBarOverflowMode.Scroll)
        .ScrollButtons(ScrollButtonsType.Auto)
        .ScrollButtonsPosition(ScrollButtonsPositionType.Start)
        .ScrollDistance(50))
     )
     ... // Additional configuration.
   )
```

For more information on the available overflow options, refer to the [Appearance documentation of the ToolBar component](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/navigation/toolbar/appearance).

## Custom Commands

The Telerik UI for ASP.NET MVC TreeList supports adding Custom Commands to its ToolBar. The following example demonstrates how to add a Custom Command to the ToolBar:

```Razor HtmlHelper
    .Toolbar(t =>
    {
        t.Custom(Html.Kendo().Template().AddComponent(c => c.Button()
               .Name("refresh")
               .Icon("arrow-rotate-cw")
               .HtmlAttributes(new { title = "Refresh" })
               .Events(ev => ev.Click("refresh"))));
        t.Spacer();
        t.Search();
    })
```

[REPL example of a Custom Command in TreeList ToolBar HtmlHelper for ASP.NET MVC](https://netcorerepl.telerik.com/QSuzwllP56E6xUe252)

> **Version note:** `ToolbarTemplateHandler` and `ToolbarTemplateId` are available in the Telerik UI for ASP.NET MVC and ASP.NET Core wrappers starting with the `2024.2.514` release. If these methods are missing, verify that the referenced `Kendo.Mvc.dll` matches the documentation and product version. Earlier releases require an upgrade to use these methods.

## ToolBar Template Handler

Telerik UI for ASP.NET MVC ToolBar introduces an overload that accept a `JavaScript` function name. It allows you to define the Template content through a client-side handler. This way, you can prevent the components from being dependent on the `unsafe-eval` and reuse the templates within multiple Components in different application pages.

```Razor HtmlHelper
    <script id="toolbar-template" type="text/x-kendo-template">
         <button id="refresh"></button>
         <span class="k-spacer"></span>
         <div class="toolBar">
            <label class="position-label" for="position">Filter by position:</label>
              <input type="search" id="position" style="width: 150px"/>
            </div>
        </div>
    </script>

    <script>
        function toolbarTemplate() {
            return $("#toolbar-template").html();
        }
    </script>

    @(Html.Kendo().TreeList<Kendo.Mvc.Examples.Models.TreeList.EmployeeDirectoryModel>()
        .Name("treelist")
        .ToolbarTemplateHandler("toolbarTemplate")
        .Columns(columns =>
        {
            columns.Add().Field(f => f.FirstName).Width(250).Title("First Name");
            columns.Add().Field(e => e.LastName).Title("Last Name");
            columns.Add().Field(e => e.Position);
            columns.Add().Field(e => e.Extension).Title("Ext").Format("{0:#}").Filterable(false);
        })
        .Height(540)
        .DataSource(dataSource => dataSource
            .ServerOperation(false)
            .Read(read => read.Action("All", "EmployeeDirectory"))
            .Model(m =>
            {
                m.Id(f => f.EmployeeId);
                m.ParentId(f => f.ReportsTo);
                m.Field(f => f.FirstName);
                m.Field(f => f.LastName);
                m.Field(f => f.ReportsTo);
                m.Expanded(true);
            })
        )
    )

```

[REPL example of a ToolBar Template Handler in TreeList HtmlHelper for ASP.NET MVC](https://netcorerepl.telerik.com/wSYfwFvQ49nhSiCY33)

## ToolBar Template Id

Telerik UI for ASP.NET MVC ToolBar introduces an overload that accepts the Id of a script as an Id for the ToolBar Template for the TreeList.

```Razor HtmlHelper
	<script id="toolBarTemplate" type="text/x-kendo-template">
         <button id="refresh"></button>
         <span class="k-spacer"></span>
         <div class="toolbar">
            <label class="position-label" for="position">Filter by position:</label>
              <input type="search" id="position" style="width: 150px"/>
            </div>
        </div>
    </script>

    @(Html.Kendo().TreeList<Kendo.Mvc.Examples.Models.TreeList.EmployeeDirectoryModel>()
        .Name("treelist")
        .ToolbarTemplateId("toolBarTemplate")
        .Columns(columns =>
        {
            columns.Add().Field(f => f.FirstName).Width(250).Title("First Name");
            columns.Add().Field(e => e.LastName).Title("Last Name");
            columns.Add().Field(e => e.Position);
            columns.Add().Field(e => e.Extension).Title("Ext").Format("{0:#}").Filterable(false);
        })
        .Height(540)
        .DataSource(dataSource => dataSource
            .ServerOperation(false)
            .Read(read => read.Action("All", "EmployeeDirectory"))
            .Model(m =>
            {
                m.Id(f => f.EmployeeId);
                m.ParentId(f => f.ReportsTo);
                m.Field(f => f.FirstName);
                m.Field(f => f.LastName);
                m.Field(f => f.ReportsTo);
                m.Expanded(true);
            })
        )
    )
```

[REPL example of a ToolBar Template Id in TreeList HtmlHelper for ASP.NET MVC](https://netcorerepl.telerik.com/GouTQFbG5298UmMT40)

## Next Steps

* [Handle the Events of the Telerik UI TreeList Component for ASP.NET MVC](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/treelist/events)
* [Persist the State of the TreeList HtmlHelper for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/treelist/persist-state)
* [Use Row Template in the Telerik UI TreeList Component for ASP.NET MVC](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/treelist/row-templates)

## See Also

* [Basic Usage of the ToolBar HtmlHelper for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/toolbar)

* [Resizing of the ToolBar HtmlHelper for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/toolbar/resizing)

* [Events of the ToolBar HtmlHelper for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/toolbar/events)

* [ToolBar HtmlHelper integration with Editors (Demo)](https://demos.telerik.com/aspnet-mvc/toolbar/integration)
