From bb11b16c7c8fb776ce3edb1795815597e4761cbb Mon Sep 17 00:00:00 2001 From: Svetoslav Dimitrov Date: Tue, 28 Apr 2020 12:17:31 +0300 Subject: [PATCH 1/2] (kb): updated kb article on select on incell edit --- knowledge-base/grid-select-on-incell-edit.md | 22 +++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/knowledge-base/grid-select-on-incell-edit.md b/knowledge-base/grid-select-on-incell-edit.md index e37958e016..b5aaf54b5a 100644 --- a/knowledge-base/grid-select-on-incell-edit.md +++ b/knowledge-base/grid-select-on-incell-edit.md @@ -21,7 +21,7 @@ res_type: kb ## Description -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. +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. 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. @@ -32,6 +32,8 @@ Use the `OnEdit` and `OnUpdate` [Grid events]({%slug grid-events%}#cud-events): * 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. * The item added to the collection is with the old value, before the editing. * In the handler for the `OnUpdate` event, update the `SelectedItems` collection with the new value of the edited item to ensure data integrity. +* For non-editable cells add a [Column Template]({%slug components/grid/features/templates%}#column-template). + * Use a `
` block and add an `onclick` event with a method where the row data is added to the SelectedItems collection. >caption How to Select the row that is being edited in InCell edit mode @@ -46,8 +48,15 @@ Use the `OnEdit` and `OnUpdate` [Grid events]({%slug grid-events%}#cud-events): OnUpdate="@UpdateItem" OnEdit="@EditHandler"> - - + @* You can add the information from the non-editable row to the SelectedItems collection *@ + + + @@ -80,6 +89,13 @@ Use the `OnEdit` and `OnUpdate` [Grid events]({%slug grid-events%}#cud-events): SelectedItems = new List(selItemsList); } } + //Add the information from clicking on non-editable cell to the SelectedItems collection + public void AddToSelectedCollection(Product item) + { + var currentSelectedItems = new List(SelectedItems); + currentSelectedItems.Add(item); + SelectedItems = currentSelectedItems; + } public void UpdateItem(GridCommandEventArgs args) { From 853d8e331714a3ce3ab624ea19a82d2ebe9701fa Mon Sep 17 00:00:00 2001 From: Svetoslav Dimitrov Date: Tue, 28 Apr 2020 16:50:05 +0300 Subject: [PATCH 2/2] (kb): improvements in the demo Code --- knowledge-base/grid-select-on-incell-edit.md | 21 +++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/knowledge-base/grid-select-on-incell-edit.md b/knowledge-base/grid-select-on-incell-edit.md index b5aaf54b5a..116f6b3e33 100644 --- a/knowledge-base/grid-select-on-incell-edit.md +++ b/knowledge-base/grid-select-on-incell-edit.md @@ -79,22 +79,19 @@ Use the `OnEdit` and `OnUpdate` [Grid events]({%slug grid-events%}#cud-events): public void EditHandler(GridCommandEventArgs args) { var item = args.Item as Product; - var foundItem = SelectedItems.Where(x => x.ProductId == item.ProductId).FirstOrDefault(); - - if (foundItem == null) - { - // add the currently edited row to the selected items - var selItemsList = SelectedItems.ToList(); - selItemsList.Add(item); - SelectedItems = new List(selItemsList); - } + AddToSelectedCollection(item); } - //Add the information from clicking on non-editable cell to the SelectedItems collection + + //Add the information from clicking on non-editable cell to the SelectedItems collection public void AddToSelectedCollection(Product item) { var currentSelectedItems = new List(SelectedItems); - currentSelectedItems.Add(item); - SelectedItems = currentSelectedItems; + if(currentSelectedItems.FindIndex(x => x.ProductId == item.ProductId) == -1) + { + currentSelectedItems.Add(item); + SelectedItems = currentSelectedItems; + } + } public void UpdateItem(GridCommandEventArgs args)