Skip to content

Commit 3fee485

Browse files
890806: Added documentation for exception handling
1 parent 4fe8cee commit 3fee485

File tree

4 files changed

+147
-0
lines changed

4 files changed

+147
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public IActionResult Index()
2+
{
3+
var tree = TreeData.GetDefaultData();
4+
ViewBag.dataSource = tree;
5+
return View();
6+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<ejs-treegrid id="TreeGrid" dataSource="@ViewBag.dataSource" height="400" childMapping="Children" treeColumnIndex="1" actionFailure="actionFailure" >
2+
<e-treegrid-editsettings allowAdding="true" allowEditing="true" allowDeleting="true"></e-treegrid-editsettings>
3+
<e-treegrid-columns>
4+
<e-treegrid-column field="TaskId" headerText="Task ID" textAlign="Right" width="100"></e-treegrid-column>
5+
<e-treegrid-column field="TaskName" headerText="Task Name" editType="stringedit" width="190"></e-treegrid-column>
6+
<e-treegrid-column field="StartDate" headerText="Start Date" editType="datepickeredit" textAlign="Right" format="yMd" type="date" width="130"></e-treegrid-column>
7+
<e-treegrid-column field="Duration" headerText="Duration" editType="numericedit" textAlign="Right" width="120"></e-treegrid-column>
8+
</e-treegrid-columns>
9+
</ejs-treegrid>
10+
<script>
11+
function actionFailure(e) {
12+
var span = document.createElement('span');
13+
this.element.parentNode.insertBefore(span, this.element);
14+
span.style.color = '#FF0000'
15+
span.innerHTML = e.error[0];
16+
}
17+
</script>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
public class HomeController : Controller
2+
{
3+
public ActionResult Index()
4+
{
5+
return View(TreeGridItems.GetTreeData());
6+
}
7+
}
8+
public class TreeGridItems
9+
{
10+
public TreeGridItems() { }
11+
public int TaskId { get; set; }
12+
public string TaskName { get; set; }
13+
public DateTime StartDate { get; set; }
14+
public int Duration { get; set; }
15+
public List<TreeGridItems> Children { get; set; }
16+
17+
public static List<TreeGridItems> GetTreeData()
18+
{
19+
List<TreeGridItems> BusinessObjectCollection = new List<TreeGridItems>();
20+
21+
TreeGridItems Record1 = null;
22+
23+
Record1 = new TreeGridItems()
24+
{
25+
TaskId = 1,
26+
TaskName = "Planning",
27+
StartDate = new DateTime(2016, 06, 07),
28+
Duration = 5,
29+
Children = new List<TreeGridItems>(),
30+
};
31+
TreeGridItems Child1 = new TreeGridItems()
32+
{
33+
TaskId = 2,
34+
TaskName = "Plan timeline",
35+
StartDate = new DateTime(2016, 06, 07),
36+
Duration = 5
37+
};
38+
39+
TreeGridItems Child2 = new TreeGridItems()
40+
{
41+
TaskId = 3,
42+
TaskName = "Plan budget",
43+
StartDate = new DateTime(2016, 06, 07),
44+
Duration = 5
45+
};
46+
TreeGridItems Child3 = new TreeGridItems()
47+
{
48+
TaskId = 4,
49+
TaskName = "Allocate resources",
50+
StartDate = new DateTime(2016, 06, 07),
51+
Duration = 5
52+
};
53+
Record1.Children.Add(Child1);
54+
Record1.Children.Add(Child2);
55+
Record1.Children.Add(Child3);
56+
TreeGridItems Record2 = new TreeGridItems()
57+
{
58+
TaskId = 6,
59+
TaskName = "Design",
60+
StartDate = new DateTime(2021, 08, 25),
61+
Duration = 3,
62+
Children = new List<TreeGridItems>()
63+
};
64+
TreeGridItems Child5 = new TreeGridItems()
65+
{
66+
TaskId = 7,
67+
TaskName = "Software Specification",
68+
StartDate = new DateTime(2021, 08, 25),
69+
Duration = 3
70+
};
71+
72+
TreeGridItems Child6 = new TreeGridItems()
73+
{
74+
TaskId = 8,
75+
TaskName = "Develop prototype",
76+
StartDate = new DateTime(2021, 08, 25),
77+
Duration = 3
78+
};
79+
TreeGridItems Child7 = new TreeGridItems()
80+
{
81+
TaskId = 9,
82+
TaskName = "Get approval from customer",
83+
StartDate = new DateTime(2024, 06, 27),
84+
Duration = 2
85+
};
86+
Record2.Children.Add(Child5);
87+
Record2.Children.Add(Child6);
88+
Record2.Children.Add(Child7);
89+
BusinessObjectCollection.Add(Record1);
90+
BusinessObjectCollection.Add(Record2);
91+
return BusinessObjectCollection;
92+
}
93+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@using Syncfusion.EJ2.Grids
2+
@model List<TreeGridSample.Controllers.TreeGridItems>
3+
4+
@(Html.EJS().TreeGrid("TreeGrid").DataSource((IEnumerable<object>)ViewBag.datasource)
5+
.EditSettings(edit =>
6+
{
7+
edit.AllowAdding(true);
8+
edit.AllowDeleting(true);
9+
edit.AllowEditing(true);
10+
})
11+
.Columns(col =>
12+
{
13+
col.Field("TaskId").HeaderText("Task ID").Width(120)
14+
.TextAlign(TextAlign.Right).Add();
15+
col.Field("TaskName").HeaderText("Task Name").Add();
16+
col.Field("StartDate").HeaderText("Start Date").Width(150).Format("yMd")
17+
.EditType("datepickeredit").TextAlign(TextAlign.Right).Add();
18+
col.Field("Duration").HeaderText("Duration").Width("110").EditType("numericedit")
19+
.Edit(new { @params = new { format = "n" } }).TextAlign(TextAlign.Right).Add();
20+
21+
}).Height(400).ChildMapping("Children").ActionFailure("actionFailure").TreeColumnIndex(1).Render())
22+
23+
< script >
24+
function actionFailure(args) {
25+
var treegrid = document.getElementById("TreeGrid").ej2_instances[0];
26+
var span = document.createElement('span');
27+
treegrid.element.parentNode.insertBefore(span, treegrid.element);
28+
span.style.color = '#FF0000'
29+
span.innerHTML = args.error[0];
30+
}
31+
</ script >

0 commit comments

Comments
 (0)