Destroy Action removing before going to controller

3 posts, 0 answers
  1. Ezequiel
    Ezequiel avatar
    36 posts
    Member since:
    Oct 2011

    Posted 22 Apr 2014 Link to this post

    Not sure if I'm missing something, but I have a destroy action in my grid and it's removing the row before even reaching Controller Method.
    and then, if I get any error, the row is not in the grid anymore.
    Destroy Method on Controller:
    public ActionResult DestroyCommission([DataSourceRequest]DataSourceRequest request, EditableCommission editable)
     {
         ModelState.AddModelError("Id", "Error");
           
         return Json(new[] { editable }.ToDataSourceResult(request, ModelState));
     }

    My Grid:
    <% this.Html.Kendo().Grid<EditableCommission>().Name("GridCommission").ToolBar(bar => bar.Create())
    .DataSource(ds => ds.Ajax().Batch(false).ServerOperation(false)
    .Read(read => read.Action("ReadCommission", "Commission").Data("getParam"))
    .Create(create => create.Action("UpdateCommission", "CadastrarPedido").Data("getParam"))
    .Update(update => update.Action("UpdateCommission", "CadastrarPedido").Data("getParam"))
    .Destroy(destroy => destroy.Action("DestroyCommission", "Commission").Data("getParam"))
    .Events(ev => ev.Error("error_handler.bind({WidgetID: '#GridCommission'})"))
                                    .Model(model =>
                                        {
                                            model.Id(p => p.Id);
                                        }))
                            .Events(events =>
                            {
                                events.Save("onSave");
                                events.Edit("onEdit");
                            })                                  
                            .Columns(columns =>
                            {
                                columns.Bound(o => o.Id).Hidden(true);
                                columns.Bound(c => c.AgentId).Hidden(true);
                                columns.Bound(c => c.Agent).ClientTemplate("#=AgentName#").Width(180);
                                columns.Bound(o => o.Percentage).Width(95).Format("{0:N2}");
                                columns.Bound(o => o.Value).Width(90).Format("{0:N4}");
                                columns.Command(commands =>
                                {
                                    commands.Edit();
                                    commands.Destroy();
                                }).Width(120);
                            })
                            .Pageable(page => page.Refresh(true).PreviousNext(false).Input(false).Numeric(false).PageSizes(false))
                            .Editable(edit => edit.Mode(Kendo.Mvc.UI.GridEditMode.PopUp))
                            .Render(); %>

    Am I missing something?
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 24 Apr 2014 Link to this post

    Hello Ezequiel,

    I am afraid it is not possible to prevent the row from removing. I can suggest you to use error event of the dataSource to re-load the current page so all the records are again visible.

    function onDataSourceError (e) {
       //if e...
        this.read();
    }

    I am sorry for any inconvenience caused.

    Kind Regards,
    Petur Subev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 24 Apr 2014 Link to this post

    Hello again Ezequiel,

    Instead of performing read I can suggest you to do this.cancelChange() in the error handler.

    http://docs.telerik.com/kendo-ui/api/framework/datasource#methods-cancelChanges

    Kind Regards,
    Petur Subev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top