Wednesday, March 4, 2015

Cancel/Close the Grid Popup Editor Window

I had a requirement that if a condition was met, when a user clicked Add New Record, it would close the popup window, and display a message instead, accomplished with js like this:

function editmode(e) {
        if (e.model.isNew()) {
            var target = $("#cathTestDate").data("kendoDropDownList");
            var len = target.dataSource.data().length;
            e.preventDefault();
            this.editRow($(e.currentTarget).closest("tr"));
            alert(len);
        }
    }

 Declare in the grid:

@(Html.Kendo().Grid<Model.Models.CathReport>()
            .Name("cathreportgrid")
            .Events(e => {
                e.Edit("editmode");
            })

1 comment:

  1. This works:
    var uid = $(".k-edit-form-container").closest("[data-role=window]").data("uid"),
    model = $("#myprojectsgv").data("kendoGrid").dataSource.getByUid(uid);
    if (model.projectStatusID == 2)
    {
    e.preventDefault();
    $("#myprojectsgv").data("kendoGrid").closeCell();
    }

    ReplyDelete