Skip to content

Commit 7289a36

Browse files
docs(grid): 0.5 to 1.0 change in API
1 parent 5b3b3c3 commit 7289a36

File tree

6 files changed

+109
-66
lines changed

6 files changed

+109
-66
lines changed

components/grid/columns/command.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,37 @@ The command column of a grid allows you to initiate [inline]({%slug components/g
1414

1515
To define it, add a `TelerikGridCommandColumn` in the `TelerikGridColumns` collection of a grid. The command column takes a collection of `TelerikGridCommandButton` instances that invoke the commands. It also offers the `Title` property so you can set its header text.
1616

17-
>tip The lists below showcase the available features and their use, and after them you can find a code example that shows declarations and handling.
17+
>tip The lists below showcase the available features and their use. After them you can find a code example that shows declarations and handling.
1818
1919
The `TelerikGridCommandButton` tag offers the following features:
2020

21-
* `Command` - the command that will be invoked. Can be one of the built-in commands, or a custom command name.
22-
* `OnClick` - the event handler that the button will fire.
21+
* `Command` - the command that will be invoked. Can be one of the built-in commands (see below), or a custom command name.
22+
* `OnClick` - the event handler that the button will fire. If used on a built-in command, this handler will fire before the [corresponding CRUD event]({%slug components/grid/editing/overview%}). Cancelling it will prevent the built-in CRUD event from firing.
2323
* `ShowInEdit` - a boolean property indicating whether the button is only visible while the user is editing/inserting data.
2424
* `ChildContent` - the text the button will render. You can also place it between the command button's opening and closing tags.
25-
* Appearance properties like Icon, Class, Enabled that are come from the underlying [Button Component features]({%slug components/button/overview%}).
25+
* Appearance properties like `Icon`, `Class`, `Enabled` that are come from the underlying [Button Component features]({%slug components/button/overview%}).
2626

2727
There are three built-in commands:
2828

2929
* `Edit` - initiates the inline or popup editing (depending on the EditMode configuration of the grid).
30-
* `Update` - performs the actual update operation after the data has been changed. Allows you to trigger an event handler to perform the data source operation.
30+
* `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 added through the grid or not.
3131
* `Cancel` - aborts the current operation (edit or insert).
3232

3333
The `OnClick` handler of the commands receives an argument of type `GridCommandEventArgs` that exposes the following properties:
3434

3535
* `IsCancelled` - set this to true to prevent the operation if the business logic requires it.
3636
* `Item` - the model item the grid row is bound to. You can use it to access the model fields and methods in order to preform the actual data source operations.
37-
* `Type` - the type of event (command).
37+
* `IsNew` - a boolean field indicating whether the item was just added through the grid interface.
38+
39+
>tip For handling CRUD operations we recommend that you use the grid events (`OnEdit`, `OnUpdate`, `OnCancel`, `OnCreate`). The `OnClick` handler is available for the built-in commands to provide consistency of the API.
3840
3941
>caption Example of adding and handling command columns for inline editing of a grid
4042
4143
````CSHTML
4244
@using Telerik.Blazor
4345
@using Telerik.Blazor.Components.Grid
4446
45-
<span>Edit will cancelled for "name 2"</span>
47+
<span>Edit will be cancelled for "name 2"</span>
4648
<br />@CustomCommandResult
4749
4850
<TelerikGrid Data=@GridData EditMode="inline"
@@ -52,9 +54,9 @@ The `OnClick` handler of the commands receives an argument of type `GridCommandE
5254
<TelerikGridColumn Field=@nameof(SampleData.Name) Title="Employee Name" />
5355
<TelerikGridColumn Field=@nameof(SampleData.HireDate) Title="Hire Date" />
5456
<TelerikGridCommandColumn>
55-
<TelerikGridCommandButton Command="Edit" Icon="edit" OnClick="@TriggerEdit">Edit</TelerikGridCommandButton>
56-
<TelerikGridCommandButton Command="Update" Icon="save" ShowInEdit="true" OnClick="@UpdateItem">Update</TelerikGridCommandButton>
57-
<TelerikGridCommandButton Command="Cancel" Icon="cancel" ShowInEdit="true" OnClick="@CancelItem">Cancel</TelerikGridCommandButton>
57+
<TelerikGridCommandButton Command="Edit" Icon="edit" OnClick="@MyEditHandler">Edit</TelerikGridCommandButton>
58+
<TelerikGridCommandButton Command="Save" Icon="save" ShowInEdit="true" OnClick="@MyUpdateHandler">Update</TelerikGridCommandButton>
59+
<TelerikGridCommandButton Command="Cancel" Icon="cancel" ShowInEdit="true" OnClick="@MyCancelHandler">Cancel</TelerikGridCommandButton>
5860
<TelerikGridCommandButton Command="MyOwnCommand" Icon="information" ShowInEdit="false" OnClick="@MyCustomCommand">My Command</TelerikGridCommandButton>
5961
</TelerikGridCommandColumn>
6062
</TelerikGridColumns>
@@ -76,30 +78,33 @@ The `OnClick` handler of the commands receives an argument of type `GridCommandE
7678
HireDate = DateTime.Now.AddDays(-x)
7779
});
7880
79-
private void TriggerEdit(GridCommandEventArgs args)
81+
private void MyEditHandler(GridCommandEventArgs args)
8082
{
8183
int empId = (args.Item as SampleData).ID;
8284
8385
//example of cancelling an event based on condition
86+
//we recommend you do this in the corresponding CRUD event
8487
if (empId == 2)
8588
{
8689
args.IsCancelled = true;
8790
}
8891
}
8992
90-
private void UpdateItem(GridCommandEventArgs args)
93+
private void MyUpdateHandler(GridCommandEventArgs args)
9194
{
9295
SampleData theUpdatedItem = args.Item as SampleData;
9396
//save changes, for example by using the model fields and/or methods
97+
//we recommend you do this in the corresponding CRUD event
9498
9599
//if you have a context added through an @inject statement, you could call its SaveChanges() method
96100
//myContext.SaveChanges();
97101
}
98102
99-
private void CancelItem(GridCommandEventArgs args)
103+
private void MyCancelHandler(GridCommandEventArgs args)
100104
{
101105
SampleData theUpdatedItem = args.Item as SampleData;
102106
//revert the changes
107+
//we recommend you do this in the corresponding CRUD event
103108
104109
//if you have a context added through an @inject statement, you could use something like this to abort changes
105110
//foreach (var entry in nwContext.ChangeTracker.Entries().Where(entry => entry.State == EntityState.Modified))

components/grid/editing/incell.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ position: 4
1010

1111
# Grid InCell Editing
1212

13-
In Cell editing allows the user has to click the cell and type the new value. When they remove focus from the input, the new value is sent to the model, where the data-access logic can move it to the actual data source.
13+
In Cell editing allows the user to click the cell and type the new value. When they remove focus from the input, the `OnUpdate` event fires, where the data-access logic can move it to the actual data source.
1414

15-
You can handle the `Update` and `Delete` events to perform the CRUD operations, as shown in the example below. At the moment, the in-cell editing does not support item creation or cancellation of changes.
15+
You can handle the `OnUpdate`, `OnCreate` and `OnDelete` events to perform the CUD operations, as shown in the example below. To add a new item, you must also add a [command column]({%slug components/grid/columns/command%}) with a `Save` command and a [toolbar]({%slug components/grid/features/toolbar%}) with an `Add` command. Cancellation of changes is not supported at the moment, you can prevent them by not calling the data access layer.
1616

1717
To enable InCell editing mode, set the `EditMode` property of the grid to `incell`, then handle the CRUD events as shown in the example below.
1818

@@ -25,10 +25,17 @@ To enable InCell editing mode, set the `EditMode` property of the grid to `incel
2525
<strong>Click a cell, edit it and click outside of the cell to see the change. Editing is prevented for the first two items.</strong>
2626
2727
<TelerikGrid Data=@MyData EditMode="incell" Pageable="true" Height="200">
28+
<TelerikGridEvents>
29+
<EventsManager OnUpdate="@UpdateHandler" OnEdit="@EditHandler" OnDelete="@DeleteHandler" OnCreate="@CreateHandler" OnCancel="@CancelHandler"></EventsManager>
30+
</TelerikGridEvents>
31+
<TelerikGridToolBar>
32+
<TelerikGridCommandButton Command="Add" Icon="add">Add Employee</TelerikGridCommandButton>
33+
</TelerikGridToolBar>
2834
<TelerikGridColumns>
2935
<TelerikGridColumn Field=@nameof(SampleData.ID) Title="ID" Editable="false" />
3036
<TelerikGridColumn Field=@nameof(SampleData.Name) Title="Name" />
3137
<TelerikGridCommandColumn>
38+
<TelerikGridCommandButton Command="Save" Icon="save" ShowInEdit="true">Update</TelerikGridCommandButton>
3239
<TelerikGridCommandButton Command="Delete" Icon="delete">Delete</TelerikGridCommandButton>
3340
</TelerikGridCommandColumn>
3441
</TelerikGridColumns>
@@ -45,25 +52,40 @@ To enable InCell editing mode, set the `EditMode` property of the grid to `incel
4552
args.IsCancelled = true;//the general approach for cancelling an event
4653
}
4754
48-
Console.WriteLine("Edit event is fired.");
55+
Console.WriteLine("Edit event is fired for column " + args.Field);
4956
}
5057
5158
public void UpdateHandler(GridCommandEventArgs args)
5259
{
53-
SampleData item = (SampleData)args.Item;
60+
string fieldName = args.Field;
61+
object newVal = args.Value; //you can cast this, if necessary, according to your model
5462
5563
//perform actual data source operation here
64+
5665
//if you have a context added through an @inject statement, you could call its SaveChanges() method
5766
//myContext.SaveChanges();
58-
Console.WriteLine("Update event is fired.");
67+
68+
Console.WriteLine("Update event is fired for " + args.Field + " with value " + args.Value);
69+
}
70+
71+
public void CreateHandler(GridCommandEventArgs args)
72+
{
73+
SampleData item = (SampleData)args.Item;
74+
75+
//perform actual data source operation here
76+
77+
Console.WriteLine("Create event is fired.");
5978
}
6079
6180
public void DeleteHandler(GridCommandEventArgs args)
6281
{
6382
SampleData item = (SampleData)args.Item;
83+
6484
//perform actual data source operation here
85+
6586
//if you have a context added through an @inject statement, you could call its SaveChanges() method
6687
//myContext.SaveChanges();
88+
6789
Console.WriteLine("Update event is fired.");
6890
}
6991

components/grid/editing/inline.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ position: 1
1010

1111
# Grid Inline Editing
1212

13-
Inline editing lets the user click an [Edit command button]({%slug components/grid/columns/command%}) on the row, and all its editable columns open up for changes. They can then click an **Update** command button to submit the changes to the model. This fires the `OnUpdate` event of the grid where your code receives the updated model so you can work with the data (for example, to call the `SaveChanges()` method of your context).
13+
Inline editing lets the user click an [Edit command button]({%slug components/grid/columns/command%}) on the row, and all its editable columns open up for changes. They can then click an `Save` command button to submit the changes to the data access layer. This fires the `OnUpdate` event of the grid where your code receives the updated model so you can work with the data (for example, to call the `SaveChanges()` method of your context).
1414

15-
In a similar fashion, the `Cancel`, `Delete` command buttons and the `Create` toolbar button fire events on the grid to let you handle the data source operations.
15+
In a similar fashion, the `Cancel` and `Delete` command buttons fire events on the grid to let you handle the data source operations.
1616

17-
You can also cancel the evens by setting the `IsCancelled` property of the event arguments to `true`. This lets you prevent the user from editing certain records, inserting or deleting items, based on your application logic.
17+
You can also cancel the events by setting the `IsCancelled` property of the event arguments to `true`. This lets you prevent the user from editing certain records, inserting or deleting items, based on your application logic.
1818

1919
To enable Inline editing in the grid, set its `EditMode` property to `inline`, then handle the CRUD events as shown in the example below.
2020

@@ -31,13 +31,13 @@ To enable Inline editing in the grid, set its `EditMode` property to `inline`, t
3131
<EventsManager OnUpdate="@UpdateHandler" OnEdit="@EditHandler" OnDelete="@DeleteHandler" OnCreate="@CreateHandler" OnCancel="@CancelHandler"></EventsManager>
3232
</TelerikGridEvents>
3333
<TelerikGridToolBar>
34-
<TelerikGridCommandButton Command="Create" Icon="add">Add Employee</TelerikGridCommandButton>
34+
<TelerikGridCommandButton Command="Add" Icon="add">Add Employee</TelerikGridCommandButton>
3535
</TelerikGridToolBar>
3636
<TelerikGridColumns>
3737
<TelerikGridColumn Field=@nameof(SampleData.ID) Title="ID" Editable="false" />
3838
<TelerikGridColumn Field=@nameof(SampleData.Name) Title="Name" />
3939
<TelerikGridCommandColumn>
40-
<TelerikGridCommandButton Command="Update" Icon="save" ShowInEdit="true">Update</TelerikGridCommandButton>
40+
<TelerikGridCommandButton Command="Save" Icon="save" ShowInEdit="true">Update</TelerikGridCommandButton>
4141
<TelerikGridCommandButton Command="Edit" Icon="edit">Edit</TelerikGridCommandButton>
4242
<TelerikGridCommandButton Command="Delete" Icon="delete">Delete</TelerikGridCommandButton>
4343
<TelerikGridCommandButton Command="Cancel" Icon="cancel" ShowInEdit="true">Cancel</TelerikGridCommandButton>
@@ -55,16 +55,16 @@ To enable Inline editing in the grid, set its `EditMode` property to `inline`, t
5555
{
5656
args.IsCancelled = true;//the general approach for cancelling an event
5757
}
58+
5859
Console.WriteLine("Edit event is fired.");
5960
}
6061
6162
public void UpdateHandler(GridCommandEventArgs args)
6263
{
6364
SampleData item = (SampleData)args.Item;
6465
65-
bool isInsert = args.IsNew;//insert or update operation
66-
6766
//perform actual data source operations here
67+
6868
//if you have a context added through an @inject statement, you could call its SaveChanges() method
6969
//myContext.SaveChanges();
7070
@@ -86,9 +86,11 @@ To enable Inline editing in the grid, set its `EditMode` property to `inline`, t
8686
8787
public void CreateHandler(GridCommandEventArgs args)
8888
{
89-
Console.WriteLine("Create event is fired.");
89+
SampleData item = (SampleData)args.Item;
9090
91-
//there is no Item associated with this event handler
91+
//perform actual data source operation here
92+
93+
Console.WriteLine("Add event is fired.");
9294
}
9395
9496
public void CancelHandler(GridCommandEventArgs args)
@@ -97,7 +99,7 @@ To enable Inline editing in the grid, set its `EditMode` property to `inline`, t
9799
98100
SampleData item = (SampleData)args.Item;
99101
100-
//perform actual data source operation here (like cancel changes on a context)
102+
//if necessary, perform actual data source operation here (like cancel changes on a context)
101103
//if you have a context added through an @inject statement, you could use something like this to abort changes
102104
//foreach (var entry in myContext.ChangeTracker.Entries().Where(entry => entry.State == EntityState.Modified))
103105
//{

0 commit comments

Comments
 (0)