aspnetmvc-120267-components-tree-list-data-editing.md
The DevExpress MVC TreeList (TreeListExtension) extension provides the built-in data editing functionality. This topic describes how to edit TreeList data.
Note
To follow the steps described below, use a data-bound TreeList extension.
You can edit TreeList data in the following way.
Add the controller action method to add new nodes to a data source.
Add the controller action method to save updated records to a data source.
Add the controller action method to delete existing records from a data source.
Define callback route values within the PartialView.
Enable the command column.
TreeList provides a full-featured client-side API that allows you to manipulate the edit form using JS code. The table below lists the available methods:
| Method | Description |
|---|---|
| ASPxClientTreeList.StartEditNewNode (via MVCxClientTreeList .StartEditNewNode ) | Switches the TreeList to edit mode and allows users to edit a newly created root node. |
| ASPxClientTreeList.StartEdit (via MVCxClientTreeList. StartEdit ) | Switches the TreeList to edit mode. |
| ASPxClientTreeList.SetEditValue (via MVCxClientTreeList .SetEditValue ) | Specifies an edit cell value. |
| ASPxCardView.IsEditing (via MVCxClientTreeList .IsEditing ) | Indicates whether the TreeList extension is in edit mode. |
| ASPxClientTreeList.UpdateEdit (via MVCxClientTreeList .UpdateEdit ) | Saves all changes and switches the TreeList extension to browse mode. |
| ASPxClientTreeList.CancelEdit (via MVCxClientTreeList .CancelEdit ) | Discards all changes and switches the TreeList extension to browse mode. |
| ASPxClientTreeList.DeleteNode (via MVCxClientTreeList .DeleteNode ) | Deletes a specified node. |
Example
The following example illustrates how to handle the client-side ASPxClientTreeList.NodeDblClick (via MVCxClientTreeList .NodeDblClick ) event to switch the TreeList to edit mode. The event handler calls the ASPxClientTreeList.StartEditNewNode (via MVCxClientTreeList .StartEditNewNode ) method that receives the processed node’s visible index and invokes an edit form.
@{
var treeList = Html.DevExpress().TreeList(settings => {
settings.Name = "TreeList";
settings.CallbackRouteValues = new { Controller = "Home", Action = "TreeListPartial" };
settings.SettingsEditing.AddNewNodeRouteValues = new { Controller = "Home", Action = "TreeListPartialAddNew" };
settings.SettingsEditing.UpdateNodeRouteValues = new { Controller = "Home", Action = "TreeListPartialUpdate" };
settings.SettingsEditing.DeleteNodeRouteValues = new { Controller = "Home", Action = "TreeListPartialDelete" };
settings.CommandColumn.Visible = true;
settings.CommandColumn.ShowNewButton = true;
settings.CommandColumn.ShowDeleteButton = true;
settings.CommandColumn.ShowEditButton = true;
settings.KeyFieldName = "CustomerID";
settings.Columns.Add("CompanyName");
settings.Columns.Add("ContactName");
settings.Columns.Add("ContactTitle");
settings.Columns.Add("Phone");
settings.ClientSideEvents.NodeDblClick = "function(s, e) { s.StartEditNewNode(e.visibleIndex); }";
});
if (ViewBag.EditError != null)
{
treeList.SetEditErrorText(ViewBag.EditError);
}
}
@treeList.Bind(Model).GetHtml()