This is a migrated thread and some comments may be shown as answers.

custom comand 'delete-button' triggers delete-action POST twice

2 Answers 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Helga
Top achievements
Rank 1
Helga asked on 23 Oct 2013, 10:22 AM
Hello,
i've implemented a custom comand delete-button for inline-editing. if clicked, a popup fades in and i have the choice to click "yes" or "no" for delete confirmation.
but on controller the delete-event is triggered twice and throws errors. what is wrong with my code? hope you can help me.

Grid:
@(Html.Kendo().Grid(Model)
    .Name("Adressen")
     
    // Datasource
    .DataSource(dataSource => dataSource
        .Ajax()
        .AutoSync(true)
        .PageSize(250)
        .Model(model =>
        {
            model.Id(p => p.Eadr);
            model.Field(p => p.Eadr).Editable(false);
            model.Field(p => p.BaLand).DefaultValue(new LiCPSAdmin2.Models.BaLand());
        })
        .Events(events => events.Error("adressen_error_handler"))
        .Create(create => create.Action("Create", "Adressen"))
        .Read(read => read.Action("Read", "Adressen"))
        .Update(update => update.Action("Edit", "Adressen"))
        .Destroy(destroy => destroy.Action("Delete", "Adressen"))
    )
     
    //Columns
    .Columns(columns =>
    {
        columns.Command(command =>
        {
            command.Edit().Text(" ");
            command.Custom(" ").Click("adressen_delete_handler").HtmlAttributes(new { name = "btn_delete"});
        }).Width(90).HtmlAttributes(new { style = "background-color: rgb(238, 238, 238)" });
        columns.Bound(p => p.Eadr).Width(90).HtmlAttributes(new { style = "text-align:center;" });
        columns.Bound(p => p.Nama);
        columns.Bound(p => p.Namb);
        columns.Bound(p => p.Namc);
        columns.Bound(p => p.Namd);
        columns.Bound(p => p.Name);
        columns.Bound(p => p.Namf);
        columns.Bound(p => p.Pstc).Width(90).HtmlAttributes(new { style = "text-align:center;" });
        columns.Bound(p => p.Ccty).Width(90).HtmlAttributes(new { style = "text-align:center;" });
        columns.Bound(p => p.BaLand.Dsca)
            .Width(200)
            .ClientTemplate(" #= BaLand ? BaLand.Dsca : '' # ")
            .Filterable(f => f.UI("statesFilter"));
    })
     
    // Events
    .Events(events => events.Edit("adressen_edit_handler")
        .DataBound("adressen_bound_handler"))
         
    // Options
    .ToolBar(toolbar => toolbar.Create().HtmlAttributes(new { enabled = "false" }))
    .Editable(editable => editable.Mode(GridEditMode.InLine).DisplayDeleteConfirmation(false))
    .Pageable()
    .Sortable()
    .Filterable(filter => filter.Extra(false))
    .Scrollable(scrollable => scrollable.Virtual(true))
    .HtmlAttributes(new { style = "height:100%;" })
    .Resizable(resize => resize.Columns(true))
    .ColumnResizeHandleWidth(5)
    .Reorderable(reordering => reordering.Columns(false))
)
Javascript:
function adressen_delete_handler(e) {
    e.preventDefault();
 
    var grid = this;
    var row = $(e.currentTarget).closest("tr");
     
    $("#delete_confirmation_popup").css({'top': ($(row).position().top + 157 + ($(row).height() / 2)), 'margin-left': (86)}).fadeIn();
 
    $("#btn_yes").off().on('click',function () {
        grid.removeRow(row);
        $("#delete_confirmation_popup").fadeOut();
    });
 
    $("#btn_no").off().on('click',function () {
        grid.cancelChanges();
        $("#delete_confirmation_popup").fadeOut();
    });
};
Thanks for help! :)

2 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 25 Oct 2013, 06:50 AM
Hi Helga,

 
Basically your current setup looks valid and it's not clear what is the exact reason for current behavior - could you please provide runable example where the issue is reproduced? This would help us pinpoint the exact reason for this behavior.

Kind Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Accepted
Helga
Top achievements
Rank 1
answered on 28 Oct 2013, 08:58 AM
Hello,
i've solved the problem. I removed the call of 'cancelChanges()' in the 'Abort'-Function of the Delete-Popup and everything worked fine.
The post is triggered once. Don't ask me why...

$("#btn_no").off().on('click',function () {
        grid.cancelChanges();
        $("#delete_confirmation_popup").fadeOut();
    });
Thanks for Help.
Tags
Grid
Asked by
Helga
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Helga
Top achievements
Rank 1
Share this question
or