Batch Editing in ASP.NET MVC Tree Grid Component

21 Dec 20221 minute to read

In Batch edit mode, when you double-click on the treegrid cell, the target cell goes into edit state.
You can bulk save (added, changed and deleted data in the single request) to data source by clicking on the toolbar’s Update button or by externally invoking the batchSave method.
To enable Batch edit, set the EditSettings.mode as Batch.

@using Syncfusion.EJ2.Grids

@Html.EJS().TreeGrid("BatchEditing").DataSource((IEnumerable<object>)ViewBag.datasource).EditSettings(edit =>
    {
        edit.AllowAdding(true);
        edit.AllowDeleting(true);
        edit.AllowEditing(true);
        edit.Mode(Syncfusion.EJ2.TreeGrid.EditMode.Batch);
        edit.NewRowPosition(Syncfusion.EJ2.TreeGrid.RowPosition.Below);
    }).Toolbar(new List<string>() { "Add", "Delete", "Update", "Cancel" }).Columns(col =>
    {
        col.Field("TaskId").HeaderText("Task ID").IsPrimaryKey(true).ValidationRules(new { required = true, number = true }).Width(90).TextAlign(TextAlign.Right).Add();
        col.Field("TaskName").HeaderText("Task Name").EditType("stringedit").ValidationRules(new { required = true }).Width(220).Add();
        col.Field("StartDate").HeaderText("Start Date").Format("yMd").TextAlign(TextAlign.Right).Width(130).EditType("datepickeredit").ValidationRules(new { date = true }).Add();
        col.Field("Duration").HeaderText("Duration").Width(100).TextAlign(TextAlign.Right).EditType("numericedit").ValidationRules(new { number = true, min = 0 }).Edit(new { @params = new { format = "n" } }).Add();
        col.Field("Progress").HeaderText("Progress").Width(80).TextAlign(TextAlign.Right).EditType("numericedit").ValidationRules(new { number = true, min = 0 }).Edit(new { @params = new { format = "n" } }).Add();
        col.Field("Priority").HeaderText("Priority").Width(90).EditType("stringedit").ValidationRules(new { required = true }).Add();
    }).IdMapping("TaskId").ParentIdMapping("ParentId").TreeColumnIndex(1).Height(400).Render()
public IActionResult Index()
{
    var tree = TreeData.GetDefaultData();
    ViewBag.dataSource = tree;
    return View();
}

NOTE

You can refer to our ASP.NET MVC Tree Grid feature tour page for its groundbreaking feature representations. You can also explore our ASP.NET MVC Tree Grid example to knows how to present and manipulate data.