New to Telerik UI for ASP.NET MVC? Start a free 30-day trial

Defines the fluent interface for configuring the TreeView component.

Definition

Constructors

Initializes a new instance of the TreeViewBuilder class.

C#
public TreeViewBuilder(TreeView component)
Parameters:componentTreeView

The component.

Methods

Configures the animation effects of the widget.

C#
public TreeViewBuilder Animation(Action<ExpandableAnimationBuilder> animationAction)
Parameters:animationActionAction<ExpandableAnimationBuilder>

The action which configures the animation effects.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.Animation(animation =&gt;
{
animation.Expand(open =&gt;
{
open.SlideIn(SlideDirection.Down);
});
})
)

Use to enable or disable animation of the TreeView.

C#
public TreeViewBuilder Animation(bool enable)
Parameters:enablebool

The boolean value.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.Animation(false) //toggle effect
)

Controls whether to bind the widget to the DataSource on initialization.

C#
public TreeViewBuilder AutoBind(bool autoBind)
Parameters:autoBindboolReturns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.AutoBind(false)
)

If set to true the widget will auto-scroll the containing element when the mouse/finger is close to the top/bottom of it.

C#
public TreeViewBuilder AutoScroll(bool value)
Parameters:valuebool

The value that configures the autoscroll.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("treeview")
.AutoScroll(true)
)

Binds the TreeView to a list of objects. The TreeView will create a hierarchy of items using the specified mappings.

C#
public TreeViewBuilder BindTo(IEnumerable dataSource, Action<NavigationBindingFactory<TreeViewItem>> factoryAction)
Parameters:dataSourceIEnumerable

The data source.

factoryActionAction<NavigationBindingFactory<TreeViewItem>>

The action which will configure the mappings

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.BindTo(Model, mapping =&gt; mapping
.For&lt;Customer&gt;(binding =&gt; binding
.Children(c =&gt; c.Orders) // The "child" items will be bound to the "Orders" property
.ItemDataBound((item, c) =&gt; item.Text = c.ContactName) // Map "Customer" properties to TreeViewItem properties
)
.For&lt;Order&lt;(binding =&gt; binding
.Children(o =&gt; null) // "Orders" do not have child objects so return "null"
.ItemDataBound((item, o) =&gt; item.Text = o.OrderID.ToString()) // Map "Order" properties to TreeViewItem properties
)
)
)

Binds the TreeView to a list of items. Use if a hierarchy of items is being sent from the controller; to bind the TreeView declaratively, use the Items() method.

C#
public TreeViewBuilder BindTo(IEnumerable<TreeViewItemModel> items)
Parameters:itemsIEnumerable<TreeViewItemModel>

The list of items

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.BindTo(model)
)

Binds the TreeView to a sitemap

C#
public TreeViewBuilder BindTo(string viewDataKey, Action<TreeViewItem, SiteMapNode> siteMapAction)
Parameters:viewDataKeystring

The view data key.

siteMapActionAction<TreeViewItem, SiteMapNode>

The action to configure the item.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.BindTo("examples", (item, siteMapNode) =&gt;
{
})
)

Binds the TreeView to a sitemap.

C#
public TreeViewBuilder BindTo(string viewDataKey)
Parameters:viewDataKeystring

The view data key.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.BindTo("examples")
)

Binds the TreeView to a list of objects. The TreeView will be "flat" which means a TreeView item will be created for every item in the data source.

C#
public TreeViewBuilder BindTo<T>(IEnumerable<T> dataSource, Action<TreeViewItem, T> itemDataBound)
Parameters:dataSourceIEnumerable<T>

The data source.

itemDataBoundAction<TreeViewItem, T>

The action executed for every data bound item.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.BindTo(new []{"First", "Second"}, (item, value) =&gt;
{
item.Text = value;
})
)

Configures the rendering of the checkboxes in the TreeView.

C#
public TreeViewBuilder Checkboxes(Action<TreeViewCheckboxesBuilder> configure)
Parameters:configureAction<TreeViewCheckboxesBuilder>

The action that configures the checkboxes settings.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.Checkboxes(config =&gt; config
.CheckChildren(true)
)
)

Enables or disables the rendering of the checkboxes in the TreeView.

C#
public TreeViewBuilder Checkboxes(bool enabled)
Parameters:enabledbool

A boolean value that toggles the rendering of the checkboxes.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.Checkboxes(true)
)

Defines the template that renders the checkboxes in the TreeView. The available fields in the template are:

  • item: The data item of the given node.
  • treeview: The TreeView options.
C#
public TreeViewBuilder CheckboxTemplate(string template)
Parameters:templatestring

The value that configures the checkbox template.

Returns:

TreeViewBuilder

Example:
C#
@(Html.Kendo().TreeView()
.Name("TreeView")
.Checkboxes(checkboxes =&gt; checkboxes
.Name("checkedFiles")
.CheckChildren(true)
)
.CheckboxTemplate("&lt;input type='checkbox' name='checkedFiles[#= item.id #]' value='true' /&gt;")
)

Defines the template that renders the checkboxes in the TreeView. The available fields in the template are:

  • item: The data item of the given node.
  • treeview: The TreeView options.
C#
public TreeViewBuilder CheckboxTemplate<TModel>(TemplateBuilder<TModel> template)
Parameters:templateTemplateBuilder<TModel>

A Template component that configures the checkbox template.

Returns:

TreeViewBuilder

Example:
C#
@(Html.Kendo().TreeView()
.Name("TreeView")
.Checkboxes(checkboxes =&gt; checkboxes
.Name("checkedFiles")
.CheckChildren(true)
)
.CheckboxTemplate(Html.Kendo().Template().AddHtml("&lt;input type='checkbox' name='checkedFiles[${data.item.id}]' value='true' /&gt;"))
)

Defines the template that renders the checkboxes in the TreeView. The available fields in the template are:

  • item: The data item of the given node.
  • treeview: The TreeView options.
C#
public TreeViewBuilder CheckboxTemplateHandler(string template)
Parameters:templatestring

The JavaScript function that will return the checkbox template.

Returns:

TreeViewBuilder

Example:
C#
@(Html.Kendo().TreeView()
.Name("TreeView")
.Checkboxes(checkboxes =&gt; checkboxes
.Name("checkedFiles")
.CheckChildren(true)
)
.CheckboxTemplateHandler("getCheckBoxTemplate")
)
&lt;script&gt;
function getCheckBoxTemplate(data) {
return `&lt;input type='checkbox' name='checkedFiles[${data.item.id}]' value='true' /&gt;`;
}
&lt;/script&gt;

Defines the template that renders the checkboxes in the TreeView. The available fields in the template are:

  • item: The data item of the given node.
  • treeview: The TreeView options.
C#
public TreeViewBuilder CheckboxTemplateId(string templateId)
Parameters:templateIdstring

The "id" attribute of the external Kendo UI Template.

Returns:

TreeViewBuilder

Example:
C#
@(Html.Kendo().TreeView()
.Name("TreeView")
.Checkboxes(checkboxes =&gt; checkboxes
.Name("checkedFiles")
.CheckChildren(true)
)
.CheckboxTemplateId("checkBoxTemplate")
)
&lt;script id="checkBoxTemplate" type="text/x-kendo-template"&gt;
&lt;input type='checkbox' name='checkedFiles[#= item.id #]' value='true' /&gt;
&lt;/script&gt;

Defines the template that renders the checkboxes in the TreeView. The available fields in the template are:

  • item: The data item of the given node.
  • treeview: The TreeView options.
C#
public TreeViewBuilder CheckboxTemplateView(MvcHtmlString template)
Parameters:templateMvcHtmlString

The Razor View that contains the checkbox template.

Returns:

TreeViewBuilder

Example:
C#
@(Html.Kendo().TreeView()
.Name("TreeView")
.Checkboxes(checkboxes =&gt; checkboxes
.Name("checkedFiles")
.CheckChildren(true)
)
.CheckboxTemplateView(Html.Partial("TemplateView"))
)

Sets the field of the data item that provides the icon name of the nodes. If an array, each level uses the field that is at the same index in the array, or the last item in the array.

C#
public TreeViewBuilder DataIconField(params string[] value)
Parameters:valuestring[]

The value that configures the dataiconfield.

Returns:

TreeViewBuilder

Sets the field of the data item that provides the image URL of the TreeView nodes.

C#
public TreeViewBuilder DataImageUrlField(string value)
Parameters:valuestring

The value that configures the dataimageurlfield.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("treeview")
.DataImageUrlField("ImageUrl")
)

Configure the DataSource of the component

C#
public TreeViewBuilder DataSource(Action<HierarchicalDataSourceBuilder<object>> configurator)
Parameters:configuratorAction<HierarchicalDataSourceBuilder<object>>

The action that configures the DataSource.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.DataSource(dataSource =&gt; dataSource
.Read(read =&gt; read
.Action("Employees", "TreeView")
)
)
)
C#
public TreeViewBuilder DataSource(string dataSourceId)
Parameters:dataSourceIdstringReturns:

TreeViewBuilder

Sets the field of the data item that provides the sprite CSS class of the nodes. If an array, each level uses the field that is at the same index in the array, or the last item in the array.

C#
public TreeViewBuilder DataSpriteCssClassField(string value)
Parameters:valuestring

The value that configures the dataspritecssclassfield.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("treeview")
.DataSpriteCssClassField("SpriteCssClass")
)

Sets the field of the data item that provides the text content of the nodes. If an array, each level uses the field that is at the same index in the array, or the last item in the array.

C#
public TreeViewBuilder DataTextField(params string[] value)
Parameters:valuestring[]

The value that configures the datatextfield.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("treeview")
.DataTextField(new string[] { "CategoryName", "ProductName"})
)

Sets the field of the data item that provides the link URL of the nodes.

C#
public TreeViewBuilder DataUrlField(string value)
Parameters:valuestring

The value that configures the dataurlfield.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("treeview")
.DataUrlField("DataUrlField")
)

Allows disabling click move click interaction as an alternative of dragging. Disables (false) or enables (true) the click move click interaction as an alternative of dragging. The alternative is disabled by default.

C#
public TreeViewBuilder DragAndDrop(Action<TreeViewDragAndDropBuilder> configure)
Parameters:configureAction<TreeViewDragAndDropBuilder>

Builder of the treeview drag & drop configuration.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.DragAndDrop(config =&gt; config
.ClickMoveClick(true)
)
)

Disables (false) or enables (true) drag-and-drop of the nodes. If configured as an object allows disabling click move click interaction as an alternative of dragging.

C#
public TreeViewBuilder DragAndDrop(bool value)
Parameters:valuebool

If true, drag & drop is enabled.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.Items(items =&gt;
{
items.Add().Text("First Item");
items.Add().Text("Second Item");
})
.DragAndDrop(true)
)

Configures the client-side events.

C#
public TreeViewBuilder Events(Action<TreeViewEventBuilder> clientEventsAction)
Parameters:clientEventsActionAction<TreeViewEventBuilder>

The client events action.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.Events(events =&gt;
.OnDataBinding("onDataBinding")
.OnItemDataBound("onItemDataBound")
)
)

Expand all the items.

C#
public TreeViewBuilder ExpandAll(bool value)
Parameters:valuebool

If true all the items will be expanded.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.ExpandAll(true)
)

Select item depending on the current URL.

C#
public TreeViewBuilder HighlightPath(bool value)
Parameters:valuebool

If true the item will be highlighted.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.HighlightPath(true)
)

Callback for each item.

C#
public TreeViewBuilder ItemAction(Action<TreeViewItem> action)
Parameters:actionAction<TreeViewItem>

Action, which will be executed for each item.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.ItemAction(item =&gt;
{
item
.Text(...)
.HtmlAttributes(...);
})
)

Defines the items in the TreeView

C#
public TreeViewBuilder Items(Action<TreeViewItemFactory> addAction)
Parameters:addActionAction<TreeViewItemFactory>

The add action.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.Items(items =&gt;
{
items.Add().Text("First Item");
items.Add().Text("Second Item");
})
)

Allows the treeview to fetch the entire datasource at initialization time.

C#
public TreeViewBuilder LoadOnDemand(bool value)
Parameters:valuebool

Whether the datasource should be loaded on demand.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.LoadOnDemand(false)
)

The text messages displayed in the widget. Use it to customize or localize the messages.

C#
public TreeViewBuilder Messages(Action<TreeViewMessagesSettingsBuilder> configurator)
Parameters:configuratorAction<TreeViewMessagesSettingsBuilder>

The action that configures the messages.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("treeview")
.Messages(m =&gt; m.Loading("Root items are loading"))
)

Defines the security trimming functionality of the component

C#
public TreeViewBuilder SecurityTrimming(Action<SecurityTrimmingBuilder> securityTrimmingAction)
Parameters:securityTrimmingActionAction<SecurityTrimmingBuilder>

The securityTrimming action.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.SecurityTrimming(builder =&gt;
{
builder.Enabled(true).HideParent(true);
})
)

Enable/disable security trimming functionality of the component.

C#
public TreeViewBuilder SecurityTrimming(bool value)
Parameters:valuebool

If true security trimming is enabled.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.SecurityTrimming(false)
)

Sets the size of the component.

C#
public TreeViewBuilder Size(ComponentSize value)
Parameters:valueComponentSize

The value that configures the size.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("treeview")
.Size(ComponentSize.Medium)
)

Defines the template for rendering each TreeView node.

C#
public TreeViewBuilder Template(string template)
Parameters:templatestring

The value that configures the node template.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.Template("&lt;span&gt;#= item.text #&lt;/span&gt;")
)

Defines the template for rendering each TreeView node.

C#
public TreeViewBuilder Template<TModel>(TemplateBuilder<TModel> template)
Parameters:templateTemplateBuilder<TModel>

A Template component that configures the node template.

Returns:

TreeViewBuilder

Example:
C#
@(Html.Kendo().TreeView()
.Name("TreeView")
.Template(Html.Kendo().Template().AddHtml("&lt;span&gt;${data.item.text}&lt;/span&gt;"))
)

Defines the template for rendering each TreeView node.

C#
public TreeViewBuilder TemplateHandler(string template)
Parameters:templatestring

The JavaScript function that will return the template content.

Returns:

TreeViewBuilder

Example:
C#
@(Html.Kendo().TreeView()
.Name("TreeView")
.TemplateHandler("getNodeTemplate")
)
&lt;script&gt;
function getNodeTemplate(data) {
return `&lt;span&gt;${data.item.text}&lt;/span&gt;`;
}
&lt;/script&gt;

Defines the template for rendering each TreeView node.

C#
public TreeViewBuilder TemplateId(string templateId)
Parameters:templateIdstring

The "id" attribute of the external Kendo UI Template.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.TemplateId("nodeTemplate")
)
&lt;script id="nodeTemplate" type="text/x-kendo-template"&gt;
&lt;span&gt;#= item.text #&lt;/span&gt;
&lt;/script&gt;

Defines the template for rendering each TreeView node.

C#
public TreeViewBuilder TemplateView(MvcHtmlString template)
Parameters:templateMvcHtmlString

The Razor View that contains the node template.

Returns:

TreeViewBuilder

Example:
C#
@( Html.Kendo().TreeView()
.Name("TreeView")
.TemplateView(Html.Partial("TemplateView"))
)