Skip to content

Commit 08b438a

Browse files
docs(grid): onadd event documentation (#806)
1 parent ad1a2f2 commit 08b438a

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

components/grid/editing/overview.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ This section explains the available events and command buttons that you need to
2727

2828
List of the available events:
2929

30-
* `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).
30+
* `OnAdd` - fires when the `Add` [command button]({%slug components/grid/columns/command%}) for a newly added item is clicked. The event is cancellable.
31+
* `OnCreate` - fires when the `Save` [command button]({%slug components/grid/columns/command%}) for a newly added item is clicked. Cancellable (cancelling it keeps the grid in Insert mode).
3132
* `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.
3233
* `OnDelete` - fires when the `Delete` command button is clicked. You can also display a [delete confirmation dialog]({%slug grid-delete-confirmation%}) before the deletion.
3334
* `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).
@@ -60,7 +61,7 @@ Editing is cancelled for the first two records.
6061
<strong>There is a deliberate delay</strong> in the data source operations in this example to mimic real life delays and to showcase the async nature of the calls.
6162
6263
<TelerikGrid Data=@MyData EditMode="@GridEditMode.Inline" Pageable="true" Height="400px"
63-
OnUpdate="@UpdateHandler" OnEdit="@EditHandler" OnDelete="@DeleteHandler" OnCreate="@CreateHandler" OnCancel="@CancelHandler">
64+
OnAdd="@AddHandler" OnUpdate="@UpdateHandler" OnEdit="@EditHandler" OnDelete="@DeleteHandler" OnCreate="@CreateHandler" OnCancel="@CancelHandler">
6465
<GridToolBar>
6566
<GridCommandButton Command="Add" Icon="add">Add Employee</GridCommandButton>
6667
</GridToolBar>
@@ -79,6 +80,15 @@ Editing is cancelled for the first two records.
7980
@logger
8081
8182
@code {
83+
async Task AddHandler(GridCommandEventArgs args)
84+
{
85+
//Set default values for new items
86+
((SampleData)args.Item).Name = "New Item Name";
87+
88+
//Cancel if needed
89+
//args.IsCancelled = true;
90+
}
91+
8292
async Task EditHandler(GridCommandEventArgs args)
8393
{
8494
SampleData item = (SampleData)args.Item;

components/grid/events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ This article explains the events available in the Telerik Grid for Blazor. They
3131

3232
## CUD Events
3333

34-
The `OnCreate`, `OnUpdate` and `OnDelete` events let you get the data item that the user changed so you can transfer the user action to the actual data source.
34+
The `OnAdd`, `OnCreate`, `OnUpdate` and `OnDelete` events let you get the data item that the user changed so you can transfer the user action to the actual data source.
3535

3636
The `OnEdit` and `OnCancel` events let you respond to user actions - when they want to edit an item and when the want to cancel changes on an item they have been editing. You can use them to, for example, prevent editing of certain items based on some condition.
3737

components/treelist/editing/overview.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ This section explains the available events and command buttons that you need to
2727

2828
List of the available events:
2929

30-
* `OnCreate` - fires when the `Save` [command button]({%slug treelist-columns-command%}) button for a newly added item is clicked. Cancellable.
30+
* `OnAdd` - fires when the `Add` [command button]({%slug treelist-columns-command%}) for a newly added item is clicked. Cancellable.
31+
* `OnCreate` - fires when the `Save` [command button]({%slug treelist-columns-command%}) for a newly added item is clicked. Cancellable.
3132
* `OnUpdate` - fires when the `Save` command button is clicked on an existing item. Cancellable. The model reference is a copy of the original data source item.
3233
* `OnDelete` - fires when the `Delete` command button is clicked. The event is cancellable, and you can also display a [delete confirmation dialog]({%slug treelist-delete-confirmation%}) before the deletion.
3334
* `OnEdit` - fires when the user is about to enter edit mode for an existing row. Cancellable.
@@ -64,6 +65,7 @@ Editing is cancelled for the first record.
6465
6566
<TelerikTreeList Data="@Data"
6667
EditMode="@TreeListEditMode.Inline"
68+
OnAdd="@AddItem"
6769
OnUpdate="@UpdateItem"
6870
OnDelete="@DeleteItem"
6971
OnCreate="@CreateItem"
@@ -97,6 +99,15 @@ Editing is cancelled for the first record.
9799
public List<Employee> Data { get; set; }
98100
99101
// Sample CUD operations for the local data
102+
async Task AddItem(TreeListCommandEventArgs args)
103+
{
104+
//Set default values for new items
105+
((Employee)args.Item).Name = "New Employee Name";
106+
107+
//Cancel if needed
108+
//args.IsCancelled = true;
109+
}
110+
100111
async Task UpdateItem(TreeListCommandEventArgs args)
101112
{
102113
var item = args.Item as Employee;

components/treelist/events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This article explains the events available in the Telerik TreeList for Blazor. T
2828

2929
## CUD Events
3030

31-
The `OnCreate`, `OnUpdate` and `OnDelete` events let you get the data item that the user changed so you can transfer the user action to the actual data source.
31+
The `OnAdd`, `OnCreate`, `OnUpdate` and `OnDelete` events let you get the data item that the user changed so you can transfer the user action to the actual data source.
3232

3333
The `OnEdit` and `OnCancel` events let you respond to user actions - when they want to edit an item and when they want to cancel changes on an item they have been editing. You can use them to, for example, prevent editing of certain items based on some condition.
3434

0 commit comments

Comments
 (0)