Skip to content

Commit 0367315

Browse files
docs(grid,treelist):add section and kb for delete confirmation dialog (#409)
* docs(grid,treelist):add section and kb for delete confirmation dialog * chore(grid,treelist):removed kb and added a new folder in grid/treelist editing * chore(grid,treelist):small fixes as per comment
1 parent a973349 commit 0367315

File tree

11 files changed

+347
-2
lines changed

11 files changed

+347
-2
lines changed

_config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ navigation:
7979
"*components/grid/editing":
8080
title: "Editing"
8181
position: 10
82+
"*components/grid/editing/built-in-dialogs":
83+
title: "Built-in Dialogs"
84+
position: 17
8285
"*components/grid/filter":
8386
title: "Filtering"
8487
position: 22
@@ -103,6 +106,9 @@ navigation:
103106
"*components/treelist/editing":
104107
title: "Editing"
105108
position: 10
109+
"*components/treelist/editing/built-in-dialogs":
110+
title: "Built-in Dialogs"
111+
position: 17
106112
"*components/treelist/filter":
107113
title: "Filtering"
108114
position: 22

components/grid/columns/command.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ There are four built-in commands:
4343

4444
* `Add` - initiates the creation of a new item.
4545
* `Edit` - initiates the inline or popup editing (depending on the GridEditMode configuration of the grid).
46+
* `Delete` - initiates the deletion of an existing item. You can also enable a [delete confirmation dialog]({%slug grid-delete-confirmation%}).
4647
* `Save` - performs the actual update operation after the data has been changed. Triggers the `OnUpdate` or `OnCreate` event so you can perform the data source operation. Which event is triggered depends on whether the item was created or edited.
4748
* `Cancel` - aborts the current operation (edit or insert).
4849

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
title: Delete Confirmation
3+
page_title: Grid - Delete Confirmation Dialog
4+
description: Enable delete confirmation dialog in Grid for Blazor.
5+
slug: grid-delete-confirmation
6+
tags: telerik,blazor,grid,delete,confirmation,dialog
7+
published: True
8+
position: 3
9+
---
10+
11+
# Delete Confirmation Dialog
12+
The delete confirmation dialog triggers before item deletion. You can enable it by setting the `ConfirmDelete` parameter of the Grid to `true`.
13+
14+
>caption Delete Confirmation dialog
15+
16+
![](../images/grid-delete-confirmation.gif)
17+
18+
>caption Enabling of the Delete Confirmation Dialog
19+
20+
````CSHTML
21+
@* Grid with enabled Delete Confirmation Dialog *@
22+
23+
@using System.ComponentModel.DataAnnotations
24+
25+
<TelerikGrid Data=@MyData Pageable="true" Height="400px"
26+
OnDelete="@DeleteHandler" ConfirmDelete="true">
27+
<GridColumns>
28+
<GridColumn Field=@nameof(SampleData.ID) Title="ID" />
29+
<GridColumn Field=@nameof(SampleData.Name) Title="Name" />
30+
<GridCommandColumn>
31+
<GridCommandButton Command="Delete" Icon="delete">Delete</GridCommandButton>
32+
</GridCommandColumn>
33+
</GridColumns>
34+
</TelerikGrid>
35+
36+
@code {
37+
async Task DeleteHandler(GridCommandEventArgs args)
38+
{
39+
SampleData item = (SampleData)args.Item;
40+
41+
await MyService.Delete(item);
42+
43+
await GetGridData();
44+
}
45+
46+
public class SampleData
47+
{
48+
public int ID { get; set; }
49+
[Required]
50+
public string Name { get; set; }
51+
}
52+
53+
List<SampleData> MyData { get; set; }
54+
55+
async Task GetGridData()
56+
{
57+
MyData = await MyService.Read();
58+
}
59+
60+
protected override async Task OnInitializedAsync()
61+
{
62+
await GetGridData();
63+
}
64+
65+
public static class MyService
66+
{
67+
private static List<SampleData> _data { get; set; } = new List<SampleData>();
68+
69+
public static async Task<List<SampleData>> Read()
70+
{
71+
if (_data.Count < 1)
72+
{
73+
for (int i = 1; i < 50; i++)
74+
{
75+
_data.Add(new SampleData()
76+
{
77+
ID = i,
78+
Name = "Name " + i.ToString()
79+
});
80+
}
81+
}
82+
83+
return await Task.FromResult(_data);
84+
}
85+
86+
public static async Task Delete(SampleData itemToDelete)
87+
{
88+
_data.Remove(itemToDelete);
89+
}
90+
}
91+
}
92+
````
93+
94+
95+
## See Also
96+
97+
* [Live Demo: Grid Inline Editing](https://demos.telerik.com/blazor-ui/grid/editing-inline)
98+
* [Live Demo: Grid PopUp Editing](https://demos.telerik.com/blazor-ui/grid/editing-popup)
99+
* [Live Demo: Grid InCell Editing](https://demos.telerik.com/blazor-ui/grid/editing-incell)
100+
* [Live Demo: Grid Custom Editor Template](https://demos.telerik.com/blazor-ui/grid/custom-editor)
101+
* [Live Demo: Grid Custom Edit Form](https://demos.telerik.com/blazor-ui/grid/editing-custom-form)
102+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: Overview
3+
page_title: Editing - Built-in Dialogs Overview
4+
description: Enable built-in dialogs in Grid for Blazor.
5+
slug: components/grid/features/built-in-dialogs
6+
tags: telerik,blazor,grid,built,in,dialogs
7+
published: True
8+
previous_url: /grid/built-in-dialogs
9+
position: 0
10+
---
11+
12+
# Grid Built-in Dialogs
13+
You can enable built-in dialogs in Grid to provide an extra step for the end-user before a Grid operation.
14+
15+
The Grid component can use built-in dialogs for:
16+
17+
* [delete confirmation]({%slug grid-delete-confirmation%}) - displays a confirmation dialog when the user clicks the "**delete**" command button.
18+
19+
The default texts of the dialogs are exposed in the [localization]({%slug globalization-localization%}) messages of the component, and you can customize them.
20+
21+
## See Also
22+
23+
* [Live Demo: Grid Inline Editing](https://demos.telerik.com/blazor-ui/grid/editing-inline)
24+
* [Live Demo: Grid PopUp Editing](https://demos.telerik.com/blazor-ui/grid/editing-popup)
25+
* [Live Demo: Grid InCell Editing](https://demos.telerik.com/blazor-ui/grid/editing-incell)
26+
* [Live Demo: Grid Custom Editor Template](https://demos.telerik.com/blazor-ui/grid/custom-editor)
27+
* [Live Demo: Grid Custom Edit Form](https://demos.telerik.com/blazor-ui/grid/editing-custom-form)
28+
259 KB
Loading

components/grid/editing/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ List of the available events:
2727

2828
* `OnCreate` - fires when the `Save` [command button]({%slug components/grid/columns/command%}) button for a newly added item is clicked. Cancellable (cancelling it keeps the grid in Insert mode).
2929
* `OnUpdate` - fires when the `Save` command button is clicked on an existing item. Cancellable (cancelling it keeps the grid in Edit mode). The model reference is a copy of the original data source item.
30-
* `OnDelete` - fires when the `Delete` command button is clicked.
30+
* `OnDelete` - fires when the `Delete` command button is clicked. You can also display a [delete confirmation dialog]({%slug grid-delete-confirmation%}) before the deletion.
3131
* `OnEdit` - fires when the user is about to enter edit mode for an existing row. Cancellable (cancelling it prevents the item from opening for editing).
3232
* `OnCancel` - fires when the user clicks the `Cancel` command button. Allows you to undo the changes to the data in the view data. Cancellable (keeps the grid in Edit/Insert mode).
3333
* `OnRead` - fires when the grid needs data - after any data source operation like updating, creating, deleting, filtering, sorting. If you cancel the CUD events, the [OnRead]({%slug components/grid/manual-operations%}) event will not fire.

components/treelist/columns/command.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ There are four built-in commands:
4646

4747
* `Add` - initiates the creation of a new item. Can apply to rows as well, to create a child element for the current row.
4848
* `Edit` - initiates the inline or popup editing (depending on the TreeListEditMode configuration of the treelist).
49+
* `Delete` - initiates the deletion of an existing item. You can also enable a [delete confirmation dialog]({%slug treelist-delete-confirmation%}).
4950
* `Save` - performs the actual update operation after the data has been changed. Triggers the `OnUpdate` or `OnCreate` event so you can perform the data source operation. Which event is triggered depends on whether the item was created or edited.
5051
* `Cancel` - aborts the current operation (edit or insert).
5152

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
---
2+
title: Delete Confirmation
3+
page_title: TreeList - Delete Confirmation Dialog
4+
description: Enable delete confirmation dialog in TreeList for Blazor.
5+
slug: treelist-delete-confirmation
6+
tags: telerik,blazor,treelist,delete,confirmation,dialog
7+
published: True
8+
position: 3
9+
---
10+
11+
# Delete Confirmation Dialog
12+
The delete confirmation dialog triggers before item deletion. You can enable it by setting the `ConfirmDelete` parameter of the TreeList to `true`.
13+
14+
>caption Delete Confirmation dialog
15+
16+
![](../images/treelist-delete-confirmation.gif)
17+
18+
>caption Enabling of the Delete Confirmation Dialog
19+
20+
````CSHTML
21+
@* TreeList with enabled Delete Confirmation Dialog *@
22+
23+
@using System.ComponentModel.DataAnnotations
24+
25+
<TelerikTreeList Data="@Data"
26+
OnDelete="@DeleteItem"
27+
Pageable="true" Height="400px"
28+
ConfirmDelete="true">
29+
<TreeListColumns>
30+
<TreeListCommandColumn>
31+
<TreeListCommandButton Command="Delete" Icon="delete">Delete</TreeListCommandButton>
32+
</TreeListCommandColumn>
33+
<TreeListColumn Field="Name" Expandable="true" />
34+
<TreeListColumn Field="Id" />
35+
<TreeListColumn Field="EmailAddress" />
36+
<TreeListColumn Field="HireDate" />
37+
</TreeListColumns>
38+
</TelerikTreeList>
39+
40+
@code {
41+
public List<Employee> Data { get; set; }
42+
43+
async Task DeleteItem(TreeListCommandEventArgs args)
44+
{
45+
var item = args.Item as Employee;
46+
47+
await MyService.Delete(item);
48+
49+
await GetTreeListData();
50+
}
51+
52+
public class Employee
53+
{
54+
public int Id { get; set; }
55+
56+
[Required]
57+
public string Name { get; set; }
58+
public string EmailAddress { get; set; }
59+
public DateTime HireDate { get; set; }
60+
61+
public List<Employee> DirectReports { get; set; }
62+
public bool HasChildren { get; set; }
63+
64+
public override bool Equals(object obj)
65+
{
66+
if (obj is Employee)
67+
{
68+
return this.Id == (obj as Employee).Id;
69+
}
70+
return false;
71+
}
72+
}
73+
74+
async Task GetTreeListData()
75+
{
76+
Data = await MyService.Read();
77+
}
78+
79+
protected override async Task OnInitializedAsync()
80+
{
81+
await GetTreeListData();
82+
}
83+
84+
public static class MyService
85+
{
86+
private static List<Employee> _data { get; set; } = new List<Employee>();
87+
private static int LastId { get; set; } = 1;
88+
89+
public static async Task<List<Employee>> Read()
90+
{
91+
if (_data.Count < 1)
92+
{
93+
for (int i = 1; i < 15; i++)
94+
{
95+
Employee root = new Employee
96+
{
97+
Id = LastId,
98+
Name = $"root: {i}",
99+
EmailAddress = $"{i}@example.com",
100+
HireDate = DateTime.Now.AddYears(-i),
101+
DirectReports = new List<Employee>(),
102+
HasChildren = true
103+
};
104+
_data.Add(root);
105+
LastId++;
106+
107+
for (int j = 1; j < 4; j++)
108+
{
109+
int currId = LastId;
110+
Employee firstLevelChild = new Employee
111+
{
112+
Id = currId,
113+
Name = $"first level child {j} of {i}",
114+
EmailAddress = $"{currId}@example.com",
115+
HireDate = DateTime.Now.AddDays(-currId),
116+
DirectReports = new List<Employee>(),
117+
HasChildren = true
118+
};
119+
root.DirectReports.Add(firstLevelChild);
120+
LastId++;
121+
122+
for (int k = 1; k < 3; k++)
123+
{
124+
int nestedId = LastId;
125+
firstLevelChild.DirectReports.Add(new Employee
126+
{
127+
Id = LastId,
128+
Name = $"second level child {k} of {j} and {i}",
129+
EmailAddress = $"{nestedId}@example.com",
130+
HireDate = DateTime.Now.AddMinutes(-nestedId)
131+
}); ;
132+
LastId++;
133+
}
134+
}
135+
}
136+
}
137+
138+
return await Task.FromResult(_data);
139+
}
140+
141+
public static async Task Delete(Employee itemToDelete)
142+
{
143+
RemoveChildRecursive(_data, itemToDelete);
144+
}
145+
146+
static void RemoveChildRecursive(List<Employee> items, Employee item)
147+
{
148+
for (int i = 0; i < items.Count(); i++)
149+
{
150+
if (item.Equals(items[i]))
151+
{
152+
items.Remove(item);
153+
154+
return;
155+
}
156+
else if (items[i].DirectReports?.Count > 0)
157+
{
158+
RemoveChildRecursive(items[i].DirectReports, item);
159+
160+
if (items[i].DirectReports.Count == 0)
161+
{
162+
items[i].HasChildren = false;
163+
}
164+
}
165+
}
166+
}
167+
}
168+
}
169+
````
170+
171+
172+
## See Also
173+
174+
* [Live Demo: TreeList Inline Editing](https://demos.telerik.com/blazor-ui/treelist/editing-inline)
175+
* [Live Demo: TreeList PopUp Editing](https://demos.telerik.com/blazor-ui/treelist/editing-popup)
176+
* [Live Demo: TreeList InCell Editing](https://demos.telerik.com/blazor-ui/treelist/editing-incell)
177+
* [Live Demo: TreeList Custom Editor Template](https://demos.telerik.com/blazor-ui/treelist/custom-editor)
178+
* [Live Demo: TreeList Custom Edit Form](https://demos.telerik.com/blazor-ui/treelist/editing-custom-form)
179+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: Overview
3+
page_title: Editing - Built-in Dialogs Overview
4+
description: Enable built-in dialogs in TreeList for Blazor.
5+
slug: components/treelist/features/built-in-dialogs
6+
tags: telerik,blazor,treelist,built,in,dialogs
7+
published: True
8+
previous_url: /treelist/built-in-dialogs
9+
position: 0
10+
---
11+
12+
# TreeList Built-in Dialogs
13+
You can enable built-in dialogs in TreeList to provide an extra step for the end-user before a TreeList operation.
14+
15+
The TreeList component can use built-in dialogs for:
16+
17+
* [delete confirmation]({%slug treelist-delete-confirmation%}) - displays a confirmation dialog when the user clicks the "**delete**" command button.
18+
19+
The default texts of the dialogs are exposed in the [localization]({%slug globalization-localization%}) messages of the component, and you can customize them.
20+
21+
## See Also
22+
23+
* [Live Demo: TreeList Inline Editing](https://demos.telerik.com/blazor-ui/treelist/editing-inline)
24+
* [Live Demo: TreeList PopUp Editing](https://demos.telerik.com/blazor-ui/treelist/editing-popup)
25+
* [Live Demo: TreeList InCell Editing](https://demos.telerik.com/blazor-ui/treelist/editing-incell)
26+
* [Live Demo: TreeList Custom Editor Template](https://demos.telerik.com/blazor-ui/treelist/custom-editor)
27+
* [Live Demo: TreeList Custom Edit Form](https://demos.telerik.com/blazor-ui/treelist/editing-custom-form)
28+
308 KB
Loading

0 commit comments

Comments
 (0)