How to cancel grid edit mode programmatically

1 Answer 51 Views
Grid
Robert
Top achievements
Rank 1
Robert asked on 07 Dec 2021, 07:49 AM

Hi,

how can I cancel the edit mode programmatically in Inline edit mode?

1 Answer, 1 is accepted

Sort by
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.

<TelerikButton OnClick="@CancelEdit">Exit Edit Mode</TelerikButton>

<TelerikGrid @ref="@GridRef" />

@code {
    TelerikGrid<GridModel> GridRef { get; set; }

    async Task CancelEdit()
    {
        var state = GridRef.GetState();
        state.EditItem = null;
        state.InsertedItem = null;
        state.OriginalEditItem = null;
        await GridRef.SetState(state);
    }
}

I hope you find the above information useful.

Regards,
Apostolos
Progress Telerik

Learn about the important changes coming in UI for Blazor 3.0 in January 2022!
Robert
Top achievements
Rank 1
commented on 07 Dec 2021, 03:36 PM

Hi Apostolos!

Thanks for the answer.

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.

Thank you in advance!

Regards,

Apostolos
Progress Telerik

Learn about the important changes coming in UI for Blazor 3.0 in January 2022!
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Apostolos
Telerik team
Share this question
or