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

How to delete row programatically?

1 Answer 356 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Grzegorz
Top achievements
Rank 1
Grzegorz asked on 23 Aug 2013, 01:47 PM
I want to change confirmation popup from synchronous browser popup to asynchronous popup (alertify). I found some old threads in Telerik MVC Extensions (http://www.telerik.com/community/forums/aspnet-mvc/grid/delete-a-row-programmatically.aspx), but this code is not working for me.

How can I delete row programatically?
I already attached to Delete event and prevent remove row, but I can't remove it programatically on positive confirmation callback (callback was called but nothing happens).

How prevent deleting row in client side too? - return false or e.preventDefault cancel remote delete call but row was removed from view.

Here is my javascript delete handler code:
function deleteRow(e) {/* How prevent delete row in client side too - return false or e.preventDefault cancel remote delete call but row was removed from view */
    alertify.confirm("dddd", function(result) {
        if (result) {
            e.sender.removeRow(e.row); /* not removing row */
        }
    });
    return false;
}
Here is grid MVC builder code:
@(Html.Kendo().Grid(Model.Franchises)
                     .Name("franchisesGrid")
                     .Columns(columns =>
                                  {
                                      columns.Bound(p => p.Name);
                                      columns.Bound(p => p.CompanyName);
                                      columns.Command(command =>
                                                          {
                                                              command.Edit().Text(LocalizationResources.Update).CancelText(LocalizationResources.Cancel).UpdateText(LocalizationResources.OK);
                                                              command.Destroy().Text(LocalizationResources.Remove);
                                                          });
                                  })
                     .Groupable()
                     .Pageable()
                     .Sortable()
                     .Scrollable()
                     .Filterable()
                     .ColumnMenu()
                     .ToolBar(toolbar =>
                                  {
                                      toolbar.Template(@<text>
                                                            <div class="row control-group">
                                                                <div class="span10">
                                                                    <a class="btn k-btn-add k-grid-add"><span class="k-icon k-add"></span>@LocalizationResources.Create</a>
                                                                </div>
                                                            </div>
                                                        </text>);
                                  })
                     .Resizable(resize => resize.Columns(true))
                     .Reorderable(reorder => reorder.Columns(true))
                     .Editable(editable =>
                                   {
                                       editable.Mode(GridEditMode.PopUp).Window(builder => builder.Title("Title"));
                                       editable.DisplayDeleteConfirmation(false);
                                   })
                     .Events(builder => builder.Remove("deleteRow"))
                     .DataSource(dataSource => dataSource
                                                   .Ajax()
                                                   .Events(events => events.Error("error_handler"))
                                                   .Model(model => model.Id(p => p.Id))
                                                   .Read("Get", "Home")
                                                   .Create("Create", "Home")
                                                   .Update("Update", "Home")
                                                   .Destroy("Remove", "Home")))

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 27 Aug 2013, 10:58 AM
Hi Grzegorz,


Please note that the required behavior is not supported out-of-the-box and it will require custom solution, however for convenience I created small example which you can use as a baseline to achieve the desired behavior:


Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Grzegorz
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or