Using the cancel Event with JavaScript with Tag Helper

2 Answers 71 Views
Grid
Jens
Top achievements
Rank 1
Iron
Jens asked on 09 Oct 2024, 12:43 PM

We have a complicated Kendo Grid with Tag Helper notification. We need to use On Cancel Event within edit operation, by pressing Cancel button. Here is an example (but not Tag Helper)

@(Html.Kendo().Grid<MyModel>()
    .Name("grid")
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Events(events => events.Cancel("onCancel")) // JavaScript event handler
    .DataSource(dataSource => dataSource
        .Ajax()
        .Model(model => model.Id(m => m.Id))
        .Read(read => read.Action("Read", "Controller"))
        .Update(update => update.Action("Update", "Controller"))
    )
    .Columns(columns =>
    {
        columns.Bound(c => c.Id).Editable(false);
        columns.Bound(c => c.Name);
        columns.Command(command => command.Edit());
    })
)

<script>
    function onCancel(e) {
        console.log("Edit operation was canceled.");
        // e.container is the jQuery object of the edited row or cell.
        // You can use this function to handle custom logic after canceling
    }
</script>

2 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 09 Oct 2024, 03:04 PM

Hello Jens,

 

Thank you for writing to us.

You can achieve this requirement using the following approach:

<kendo-grid ... on-cancel="cancel_handler">

JS:

    function cancel_handler(e){
        alert("Editing cancelled");
    }

Here is a live sample I have prepared for your convenience:
https://netcorerepl.telerik.com/wSlOOjvp04nEl0GG26

Do you find this sample beneficial? Let me know what you think.

 

Regards,
Eyup
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Jens
Top achievements
Rank 1
Iron
answered on 10 Oct 2024, 07:15 AM
Thank you for your answer. It has helped me.
Tags
Grid
Asked by
Jens
Top achievements
Rank 1
Iron
Answers by
Eyup
Telerik team
Jens
Top achievements
Rank 1
Iron
Share this question
or