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

Destroy Action removing before going to controller

2 Answers 177 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ezequiel
Top achievements
Rank 2
Ezequiel asked on 22 Apr 2014, 01:49 PM
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 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 24 Apr 2014, 11:30 AM
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.

 
0
Petur Subev
Telerik team
answered on 24 Apr 2014, 01:59 PM
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.

 
Tags
Grid
Asked by
Ezequiel
Top achievements
Rank 2
Answers by
Petur Subev
Telerik team
Share this question
or