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

Defines the fluent API for configuring the Kendo UI TreeView

Definition

Namespace:Kendo.Mvc.UI.Fluent

Assembly:Kendo.Mvc.dll

Syntax:

C#
public class TreeViewBuilder : WidgetBuilderBase<TreeView, TreeViewBuilder>, IHtmlContent

Inheritance: objectHelperResultWidgetBuilderBase<TreeView, TreeViewBuilder>TreeViewBuilder

Implements: IHtmlContent

Inherited Members WidgetBuilderBase<TreeView, TreeViewBuilder>.ToComponent()WidgetBuilderBase<TreeView, TreeViewBuilder>.Expression(string)WidgetBuilderBase<TreeView, TreeViewBuilder>.Explorer(ModelExplorer)WidgetBuilderBase<TreeView, TreeViewBuilder>.Name(string)WidgetBuilderBase<TreeView, TreeViewBuilder>.Deferred(bool)WidgetBuilderBase<TreeView, TreeViewBuilder>.HtmlAttributes(object)WidgetBuilderBase<TreeView, TreeViewBuilder>.HtmlAttributes(IDictionary<string, object>)WidgetBuilderBase<TreeView, TreeViewBuilder>.ScriptAttributes(object, bool)WidgetBuilderBase<TreeView, TreeViewBuilder>.ScriptAttributes(IDictionary<string, object>, bool)WidgetBuilderBase<TreeView, TreeViewBuilder>.Render()WidgetBuilderBase<TreeView, TreeViewBuilder>.ToHtmlString()WidgetBuilderBase<TreeView, TreeViewBuilder>.WriteTo(TextWriter, HtmlEncoder)WidgetBuilderBase<TreeView, TreeViewBuilder>.ToClientTemplate()WidgetBuilderBase<TreeView, TreeViewBuilder>.AsModule(bool)WidgetBuilderBase<TreeView, TreeViewBuilder>.ComponentWidgetBuilderBase<TreeView, TreeViewBuilder>.ContainerHelperResult.WriteTo(TextWriter, HtmlEncoder)HelperResult.WriteActionobject.GetType()object.MemberwiseClone()object.ToString()object.Equals(object)object.Equals(object, object)object.ReferenceEquals(object, object)object.GetHashCode()...

Constructors

Initializes a new instance of the TreeViewBuilder class.

C#
public TreeViewBuilder(TreeView component)
Parameters:componentTreeView

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

Returns the current TreeViewBuilder instance.

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

Returns the current TreeViewBuilder instance.

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

If set to false the widget will not bind to the data source during initialization. In this case data binding will occur when the change event of the data source is fired. By default the widget will bind to the data source specified in the configuration.

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

The value for AutoBind

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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()
Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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 for AutoScroll

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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

Returns the current TreeViewBuilder instance.

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

Returns the current TreeViewBuilder instance.

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

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

Returns the current TreeViewBuilder instance.

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

If true or an object, renders checkboxes beside each node.

C#
public TreeViewBuilder Checkboxes()
Returns:

TreeViewBuilder

Returns the current instance of TreeViewCheckboxesSettingsBuilder .

If true or an object, renders checkboxes beside each node.

C#
public TreeViewBuilder Checkboxes(Action<TreeViewCheckboxesSettingsBuilder> configurator)
Parameters:configuratorAction<TreeViewCheckboxesSettingsBuilder>

The TreeViewCheckboxesSettingsBuilder for the checkboxes setting.

Returns:

TreeViewBuilder

Returns the current instance of TreeViewBuilder .

If true or an object, renders checkboxes beside each node.

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

Enables or disables the checkboxes option.

Returns:

TreeViewBuilder

Returns the current instance of TreeViewCheckboxesSettingsBuilder .

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

Returns the current TreeViewBuilder instance.

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

Returns the current TreeViewBuilder instance.

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 templateHandler)
Parameters:templateHandlerstring

he JavaScript function that will return the checkbox template.

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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

Returns the current TreeViewBuilder instance.

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(IHtmlContent templateView)
Parameters:templateViewIHtmlContent

The Razor View that contains the checkbox template.

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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 for DataIconField

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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

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 for DataImageUrlField

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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 HierarchicalDataSourceBuilder<TModel> that configures the DataSource of the component.

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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

Set ID of the DataSource that to be used for data binding

C#
public TreeViewBuilder DataSource(string dataSourceId)
Parameters:dataSourceIdstringReturns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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 for DataSpriteCssClassField

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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 for DataTextField

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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 for DataUrlField

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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

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()
Returns:

TreeViewBuilder

Returns the current instance of TreeViewDragAndDropSettingsBuilder .

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(Action<TreeViewDragAndDropSettingsBuilder> configurator)
Parameters:configuratorAction<TreeViewDragAndDropSettingsBuilder>

The TreeViewDragAndDropSettingsBuilder for the draganddrop setting.

Returns:

TreeViewBuilder

Returns the current instance of TreeViewBuilder .

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 enabled)
Parameters:enabledbool

Enables or disables the draganddrop option.

Returns:

TreeViewBuilder

Returns the current instance of TreeViewDragAndDropSettingsBuilder .

Configures the client-side events.

C#
public TreeViewBuilder Events(Action<TreeViewEventBuilder> configurator)
Parameters:configuratorAction<TreeViewEventBuilder>

The client events action.

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

Example:
C#
@(Html.Kendo().TreeView()
.Name("TreeView")
.Events(events =&gt; events
.Change("onChange")
)
)

Expand all the items.Applicable when local data binding is used.

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

If true all the items will be expanded.

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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

Returns the current TreeViewBuilder instance.

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

Defines the items in the TreeView

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

The add action.

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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

Indicates whether the child DataSources should be fetched lazily when parent groups get expanded. Setting this to false causes all child DataSources to be loaded at initialization time.

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

The value for LoadOnDemand

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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 TreeViewMessagesSettingsBuilder for the messages setting.

Returns:

TreeViewBuilder

Returns the current instance of TreeViewBuilder .

Sets the size of the component.

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

The value for Size

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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

Template for rendering each node.

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

The value for Template

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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

Template for rendering each node.

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

A Template component that configures the template.

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

Template for rendering each node.

C#
public TreeViewBuilder TemplateHandler(string templateHandler)
Parameters:templateHandlerstring

The handler that returs the template for Template

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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;

Template for rendering each node.

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

The ID of the template element for Template

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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;

Template for rendering each node.

C#
public TreeViewBuilder TemplateView(IHtmlContent templateView)
Parameters:templateViewIHtmlContent

The view that contains the template for Template

Returns:

TreeViewBuilder

Returns the current TreeViewBuilder instance.

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