|
@(Html.EJS().TreeGrid("TreeGrid")
.DataSource((IEnumerable<object>)ViewBag.DataSource)
EditSettings(edit => edit.AllowEditing(true).AllowDeleting(true).AllowAdding(true).NewRowPosition(Syncfusion.EJ2.TreeGrid.RowPosition.Below).Mode(Syncfusion.EJ2.TreeGrid.EditMode.Row))
.Columns(col =>
{
col.HeaderText("Manage Records").HeaderTemplate("#AddIcon").Width("130").TextAlign(TextAlign.Center).Commands(commands).Add();
}).TreeColumnIndex(1).DataBound("bound")
.Render())
@{
List<object> commands = new List<object>();
commands.Add(new { type = "add", buttonOption = new { iconCss = "e-icons e-add", cssClass = "e-flat"}, }); //bind AddIcon on custom buttons
commands.Add(new { type = "Edit", buttonOption = new { iconCss = "e-icons e-edit", cssClass = "e-flat" } });
commands.Add(new { type = "Delete", buttonOption = new { iconCss = "e-icons e-delete", cssClass = "e-flat" } });
commands.Add(new { type = "Save", buttonOption = new { iconCss = "e-icons e-update", cssClass = "e-flat" } });
commands.Add(new { type = "Cancel", buttonOption = new { iconCss = "e-icons e-cancel-icon", cssClass = "e-flat" } });
}
<script>
function bound(args) {
this.grid.commandClick = function (args) { //bind CommandClick action for add Icon
if (args.commandColumn.type == "add") {
var treeGridObj = document.getElementsByClassName('e-treegrid')[0].ej2_instances;
treeGridObj[0].addRecord(); //using AddRecord method we can add row based on newRowPosition.
}
}
} </script> |
|
@(Html.EJS().TreeGrid("TreeGrid")
.DataSource((IEnumerable<object>)ViewBag.DataSource)
.EditSettings(edit => edit.AllowEditing(true).AllowDeleting(true).AllowAdding(true).NewRowPosition(Syncfusion.EJ2.TreeGrid.RowPosition.Below).Mode(Syncfusion.EJ2.TreeGrid.EditMode.Row))
.Columns(col =>
{
col.Field("TaskID").HeaderText("Task ID").IsPrimaryKey(true).Width(110).TextAlign(TextAlign.Right)
. . .
col.HeaderText("Manage Records").HeaderTemplate("#AddIcon").Width("130").TextAlign(TextAlign.Center).Commands(commands).Add();
}).TreeColumnIndex(1).DataBound("bound")
.Render())
<script type="text/x-template" id="AddIcon">
<span class="e-icons e-add" onclick="add()"></span> //place AddIcon as HeaderTemplate
</script>
<script>
function add() {
var treeGridObj = document.getElementsByClassName('e-treegrid')[0].ej2_instances; //perform Click action for AddRecord
treeGridObj[0].addRecord()
}
</script> |
|
@Html.EJS().TreeView("tree").LoadOnDemand(false).Fields(field =>
field.Id("OrderID").ParentID("EmployeeID").
Expanded("expanded").Text("CustomerID").HasChildren("HasChild")
.DataSource(dataManager => { dataManager.Url("/Home/initialData").InsertUrl("/Home/Insert").RemoveUrl("/Home/Delete").BatchUrl("/Home/Bulk").Adaptor("UrlAdaptor").Offline(false); })).Render()
<button id="btn">RemoveNodes</button>
<button id="btn2">AddNodes</button>
|
|
//insert the record
public ActionResult Insert([FromBody]CRUDModel<OrdersDetails> value)
{
OrdersDetails.GetAllRecords().Insert(0, value.Value);
return Json(value.Value);
}
//Delete the record
public ActionResult Delete([FromBody]CRUDModel<OrdersDetails> value)
{
OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == int.Parse(value.Key.ToString())).FirstOrDefault());
var data = OrdersDetails.GetAllRecords();
return Json(data);
} |