Skip to content

Commit 5b27de1

Browse files
authored
Merge pull request #3085 from syncfusion-content/891097-actionfailure
890806: Added documentation for exception handling
2 parents bc14223 + 3fee485 commit 5b27de1

File tree

7 files changed

+211
-0
lines changed

7 files changed

+211
-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 >

ej2-asp-core-mvc/tree-grid/EJ2_ASP.MVC/getting-started-mvc.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,38 @@ By default, filtered records are shown along with its parent records. This behav
188188

189189
![ASP.NET MVC Tree Grid with Filtering](images/treegrid-sample.png)
190190

191+
## Handling errors
192+
193+
Error handling in Tree Grid identifies exceptions and notifies them through the [actionFailure](https://help.syncfusion.com/cr/aspnetmvc-js2/syncfusion.ej2.treegrid.treegrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_ActionFailure) event. When configuring the Tree Grid or enabling specific features through its API, mistakes can occur. The `actionFailure` event can be used to manage these errors. This event triggers when such mistakes happen. The `actionFailure` event handles various scenarios, including:
194+
195+
* For CRUD operations, row drag and drop, and persisiting the selection, ensure the `isPrimaryKey` property is mapped to a unique data column. Failure to do so will cause an error.
196+
* [Paging](https://ej2.syncfusion.com/aspnetmvc/documentation/tree-grid/paging) is not supported with [virtualization](https://ej2.syncfusion.com/aspnetmvc/documentation/tree-grid/virtual-scroll). Enabling `paging` with `virtualization` will result in an error.
197+
* To render the Tree Grid, map either the [dataSource](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_DataSource) or [columns](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_Columns) property. Failure to do so will result in an error.
198+
* Freeze columns by mapping either `isFrozen` or [frozenColumns](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_FrozenColumns). Enabling both properties simultaneously will result in an error.
199+
* The [detailTemplate](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_DetailTemplate) is not supported with `virtualization` and `stacked header`. Enabling them with these features will result in an error.
200+
* The [frozenRows](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_FrozenRows) and `frozenColumns` are not supported with [rowTemplate](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_RowTemplate), `detailTemplate`, and [cell editing](https://ej2.syncfusion.com/aspnetmvc/documentation/tree-grid/editing/cell-editing). Enabling them with these features will result in an error.
201+
* In `stacked header`, the `freeze` direction is incompatible with [column reordering](https://ej2.syncfusion.com/aspnetmvc/documentation/tree-grid/columns/column-reorder).
202+
* [Selection](https://ej2.syncfusion.com/aspnetmvc/documentation/tree-grid/selection/selection) functionality is not supported when using `rowTemplate`. Enabling both properties simultaneously will result in an error.
203+
* Set the [treeColumnIndex](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_TreeColumnIndex) value to display the tree structure. Make sure the value does not exceed the total column count, or it will result in an error.
204+
* For `virtualization`, do not specify height and width in percentages. Using percentages will result in an error.
205+
* When using the default filter ([filterbar](https://ej2.syncfusion.com/aspnetmvc/documentation/tree-grid/filtering/filter-bar)) type, do not apply the other [filterType](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.TreeGrid.FilterType.html) to any column in the same tree grid, as this will cause an error.
206+
* In Tree Grid, avoid enabling [idMapping](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_IdMapping) and [childMapping](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_ChildMapping) simultaneously. Enabling both properties at the same time will result in an error.
207+
* The `showCheckbox` column should only be defined in the tree column. Defining it elsewhere will result in an error.
208+
* The `textAlign` right is not applicable for tree columns in the Tree Grid. Enabling right alignment for tree columns will result in an error.
209+
210+
The following code example shows how to use the [actionFailure](https://help.syncfusion.com/cr/aspnetmvc-js2/syncfusion.ej2.treegrid.treegrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_ActionFailure) event in the Tree Grid control to display an exception when `isPrimaryKey` are not configured properly in the Tree Grid.
211+
212+
{% tabs %}
213+
{% highlight razor tabtitle="CSHTML" %}
214+
{% include code-snippet/tree-grid/getting-start-mvc/error-handling/razor %}
215+
{% endhighlight %}
216+
{% highlight c# tabtitle="HomeController.cs" %}
217+
{% include code-snippet/tree-grid/getting-start-mvc/error-handling/errorHandling.cs %}
218+
{% endhighlight %}
219+
{% endtabs %}
220+
221+
![ASP.NET MVC Tree Grid with Handling errors](images/error-handling.png)
222+
191223
N> [View Sample in GitHub](https://github.com/SyncfusionExamples/ASP-NET-MVC-Getting-Started-Examples/tree/main/TreeGrid/ASP.NET%20MVC%20Razor%20Examples).
192224

193225
N> You can refer to our [ASP.NET MVC Tree Grid](https://www.syncfusion.com/aspnet-mvc-ui-controls/tree-grid) feature tour page for its groundbreaking feature representations. You can also explore our [ASP.NET MVC Tree Grid example](https://ej2.syncfusion.com/aspnetmvc/TreeGrid/Overview#/material) to knows how to present and manipulate data.

ej2-asp-core-mvc/tree-grid/EJ2_ASP.NETCORE/getting-started-core.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,38 @@ public class TreeGridItems
612612

613613
N> [View Sample in GitHub](https://github.com/SyncfusionExamples/ASP-NET-Core-Getting-Started-Examples/tree/main/TreeGrid/ASP.NET%20Core%20Tag%20Helper%20Examples).
614614

615+
## Handling errors
616+
617+
Error handling in Tree Grid identifies exceptions and notifies them through the [actionFailure](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_ActionFailure) event. When configuring the Tree Grid or enabling specific features through its API, mistakes can occur. The `actionFailure` event can be used to manage these errors. This event triggers when such mistakes happen. The `actionFailure` event handles various scenarios, including:
618+
619+
* For CRUD operations, row drag and drop, and persisiting the selection, ensure the `isPrimaryKey` property is mapped to a unique data column. Failure to do so will cause an error.
620+
* [Paging](https://ej2.syncfusion.com/aspnetcore/documentation/tree-grid/paging) is not supported with [virtualization](https://ej2.syncfusion.com/aspnetcore/documentation/tree-grid/virtual-scroll). Enabling `paging` with `virtualization` will result in an error.
621+
* To render the Tree Grid, map either the [dataSource](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_DataSource) or [columns](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_Columns) property. Failure to do so will result in an error.
622+
* Freeze columns by mapping either `isFrozen` or [frozenColumns](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_FrozenColumns). Enabling both properties simultaneously will result in an error.
623+
* The [detailTemplate](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_DetailTemplate) is not supported with `virtualization` and `stacked header`. Enabling them with these features will result in an error.
624+
* The [frozenRows](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_FrozenRows) and `frozenColumns` are not supported with [rowTemplate](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_RowTemplate), `detailTemplate`, and [cell editing](https://ej2.syncfusion.com/aspnetcore/documentation/tree-grid/editing/cell-editing). Enabling them with these features will result in an error.
625+
* In `stacked header`, the `freeze` direction is incompatible with [column reordering](https://ej2.syncfusion.com/aspnetcore/documentation/tree-grid/columns/column-reorder).
626+
* [Selection](https://ej2.syncfusion.com/aspnetcore/documentation/tree-grid/selection/selection) functionality is not supported when using `rowTemplate`. Enabling both properties simultaneously will result in an error.
627+
* Set the [treeColumnIndex](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_TreeColumnIndex) value to display the tree structure. Make sure the value does not exceed the total column count, or it will result in an error.
628+
* For `virtualization`, do not specify height and width in percentages. Using percentages will result in an error.
629+
* When using the default filter ([filterbar](https://ej2.syncfusion.com/aspnetcore/documentation/tree-grid/filtering/filter-bar)) type, do not apply the other [filterType](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.TreeGrid.FilterType.html) to columns within the same tree grid, as this will result in an error.
630+
* In Tree Grid avoid enabling [idMapping](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_IdMapping) and [childMapping](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_ChildMapping) simultaneously. Enabling both properties at the same time will result in an error.
631+
* The `showCheckbox` column should only be defined in the tree column. Defining it elsewhere will result in an error.
632+
* The `textAlign` right is not applicable for tree columns in the Tree Grid. Enabling right alignment for tree columns will result in an error.
633+
634+
The following code example shows how to use the [actionFailure](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.TreeGrid.TreeGrid.html#Syncfusion_EJ2_TreeGrid_TreeGrid_ActionFailure) event in the Tree Grid control to display an exception when `isPrimaryKey` are not configured properly in the Tree Grid.
635+
636+
{% tabs %}
637+
{% highlight cshtml tabtitle="CSHTML" %}
638+
{% include code-snippet/tree-grid/getting-start-core/error-handling/tagHelper %}
639+
{% endhighlight %}
640+
{% highlight c# tabtitle="ErrorHandling.cs" %}
641+
{% include code-snippet/tree-grid/getting-start-mvc/error-handling/errorHandling.cs %}
642+
{% endhighlight %}
643+
{% endtabs %}
644+
645+
![ASP.NET CORE Tree Grid with Handling errors](images/error-handling.png)
646+
615647
## See also
616648

617649
* [Getting Started with Syncfusion ASP.NET Core using Razor Pages](https://ej2.syncfusion.com/aspnetcore/documentation/getting-started/razor-pages/)
Loading

0 commit comments

Comments
 (0)