how can I cancel the edit mode programmatically in Inline edit mode?
1 Answer, 1 is accepted
1
Accepted
Apostolos
Telerik team
answered on 07 Dec 2021, 03:27 PM
Hi Robert,
It is possible to exit edit mode programmatically, without using the default Cancel button.
To achieve this, you can use the Grid State. We have a section that shows how to initiate editing. In your case, you will do the opposite - set the following Grid state properties to null:
InsertedItem
EditItem
OriginalEditItem
The code snippet bellow uses an OnClick event handler as an example. Note that the edited item will not be saved.
A suggestion: why not to provide a simple public method on the Grid?
Apostolos
Telerik team
commented on 08 Dec 2021, 04:11 PM
Hello Robert,
Normally, the Grid Cancel command allows users to cancel changes in inline edit mode. It appears that it is not suitable for your case.
I would like to get more details about your scenario and what brings the need to exit edit mode programmatically. This will allow us to understand your needs better.
I can confirm that using the Grid State in this way still works.
However, I want to point out that `OriginalEditItem`, `EditItem`, and `InsertedItem` are non-nullable types, so you get a warning that you cannot convert null literal to non-nullable reference type. Making them nullable would remove the warning and better communicate the intent that setting a null value can cancel the edit.
Dimo
Telerik team
commented on 16 Sep 2024, 12:05 PM
@Leland - I agree with you and I stumble on this issue myself. We have an internal task about nullable-related refactoring in our source code. The bad thing is that this task requires development effort, which does not match the resulting small business value. As a result, the priority is low.