Prevent detele last record

3 posts, 1 answers
  1. Andrey
    Andrey avatar
    50 posts
    Member since:
    Jul 2014

    Posted 17 Jun 2018 Link to this post


    I am using MVC wrappers without Edit button (Add and Delete only). What is the better way to prevent to delete very last record in the grid? I could use command().hidden(bool) but have not figured out yet how to wire JavaScript function there.


            .Columns(columns =>
                columns.Bound(p => p.PhoneID);
                columns.Bound(p => p.PhoneNumberInt);
                columns.Bound(p => p.PhoneNumberString);
                columns.Command(command => { command.Edit(); command.Destroy(); }).Width(250);
            .ToolBar(toolbar => toolbar.Create())
            .Editable(editable => editable.Mode(GridEditMode.InLine).ConfirmDelete("Delete").DisplayDeleteConfirmation("Are you sure to delete?"))
            .HtmlAttributes(new { style = "auto;" })
            .DataSource(dataSource => dataSource
                .Model(model => model.Id(p => p.PhoneID))
                .Create(update => update.Action("EditingInline_Create", "Grid"))
                .Read(read => read.Action("EditingInline_Read", "Grid"))
                .Update(update => update.Action("EditingInline_Update", "Grid"))
                .Destroy(update => update.Action("EditingInline_Destroy", "Grid"))
                .Events(e => e.Error("onPhoneError"))


  2. Answer
    Georgi avatar
    695 posts

    Posted 19 Jun 2018 Link to this post

    Hi Andrey,

    Based on the provided information I assume that the requirement is to hide the destroy command in case the grid contains only a single record. Please correct me if I am wrong.

    A possible solution is to pass a handler to the Visible property of the command.

    // command configuration
    // handler
        function handler(e) {     
            return $('\#grid').data('kendoGrid') > 1;

    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Andrey
    Andrey avatar
    50 posts
    Member since:
    Jul 2014

    Posted 20 Jun 2018 in reply to Georgi Link to this post

    Works great. Thank you!
Back to Top