Skip to content

Commit 0da459d

Browse files
svdimitrmarin-bratanov
authored andcommitted
Update Selection in incell edit KB (#61)
* (kb): updated kb article on select on incell edit * (kb): improvements in the demo Code
1 parent f32cb31 commit 0da459d

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

knowledge-base/grid-select-on-incell-edit.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ res_type: kb
2121

2222
## Description
2323

24-
When using the [InCell]({%slug components/grid/editing/incell%}) Editing Mode, I want the row that is currently edited to be selected. I want the user to get the current row selected when they edit it.
24+
When using the [InCell]({%slug components/grid/editing/incell%}) Editing Mode, I want the row that is currently edited to be selected. I want the user to get the current row selected by clicking both in editable and non-editable cells.
2525

2626
By default, the click action opens a cell for editing and does not select a row to avoid an ambiguous action, and so rows can only be selected with the dedicated grid selection column.
2727

@@ -32,6 +32,8 @@ Use the `OnEdit` and `OnUpdate` [Grid events]({%slug grid-events%}#cud-events):
3232
* In the handler for the `OnEdit` event add the currently edited item, passed to the method through the object of type `GridCommandEventArgs`, into the `SelectedItems` collection.
3333
* The item added to the collection is with the old value, before the editing.
3434
* In the handler for the `OnUpdate` event, update the `SelectedItems` collection with the new value of the edited item to ensure data integrity.
35+
* For non-editable cells add a [Column Template]({%slug components/grid/features/templates%}#column-template).
36+
* Use a `<div>` block and add an `onclick` event with a method where the row data is added to the SelectedItems collection.
3537

3638
>caption How to Select the row that is being edited in InCell edit mode
3739
@@ -46,8 +48,15 @@ Use the `OnEdit` and `OnUpdate` [Grid events]({%slug grid-events%}#cud-events):
4648
OnUpdate="@UpdateItem"
4749
OnEdit="@EditHandler">
4850
<GridColumns>
49-
<GridCheckboxColumn SelectAllMode="@GridSelectAllMode.All"></GridCheckboxColumn>
50-
<GridColumn Field=@nameof(Product.ProductId) Title="Product Id" Editable="false" />
51+
@* You can add the information from the non-editable row to the SelectedItems collection *@
52+
<GridColumn Field=@nameof(Product.ProductId) Title="Product Id" Editable="false">
53+
<Template>
54+
@{
55+
Product item = context as Product;
56+
<div @onclick="@( () => AddToSelectedCollection(item) )">@item.ProductId</div>
57+
}
58+
</Template>
59+
</GridColumn>
5160
<GridColumn Field=@nameof(Product.ProductName) Title="Product Name" />
5261
<GridColumn Field=@nameof(Product.SupplierId) Title="Supplier Id" />
5362
<GridColumn Field=@nameof(Product.UnitPrice) Title="Unit Price" />
@@ -70,15 +79,19 @@ Use the `OnEdit` and `OnUpdate` [Grid events]({%slug grid-events%}#cud-events):
7079
public void EditHandler(GridCommandEventArgs args)
7180
{
7281
var item = args.Item as Product;
73-
var foundItem = SelectedItems.Where(x => x.ProductId == item.ProductId).FirstOrDefault();
82+
AddToSelectedCollection(item);
83+
}
7484
75-
if (foundItem == null)
85+
//Add the information from clicking on non-editable cell to the SelectedItems collection
86+
public void AddToSelectedCollection(Product item)
87+
{
88+
var currentSelectedItems = new List<Product>(SelectedItems);
89+
if(currentSelectedItems.FindIndex(x => x.ProductId == item.ProductId) == -1)
7690
{
77-
// add the currently edited row to the selected items
78-
var selItemsList = SelectedItems.ToList();
79-
selItemsList.Add(item);
80-
SelectedItems = new List<Product>(selItemsList);
91+
currentSelectedItems.Add(item);
92+
SelectedItems = currentSelectedItems;
8193
}
94+
8295
}
8396
8497
public void UpdateItem(GridCommandEventArgs args)

0 commit comments

Comments
 (0)