Search code examples
jquerykendo-uikendo-window

KendoWindow can close when its first opened, but not when its open a second time


I have some weird issue going on and I been trying to fix it over the last couple hours and have looked for answers on this but the only thing I find is the opposite. I have a Kendo Window that will close on my button click the first time that it is opened, but when I reopen the window my button click won't close it down. Everywhere I have looked people have the opposite issue. Here is my code for the window

function CustomerPopupEditor() {
    $("#showCustomerEdit").append("<div id='window'></div>");
    var myWindow = $("#window").kendoWindow({
        width: "80%",
        height: "47%",
        title: "Customer",
        content: "/Customer/CustomerEditor",
        modal: true,
        actions: [
            "Close"
        ],
        close: function (e) {
            $("#window").empty();
        }
    }).data("kendoWindow");
    myWindow.center().open();
}

here is my kendo toolbar that opens the window

template: "<button type='button' onClick='CustomerPopupEditor()' class='btn btn-warning'><span class='glyphicon glyphicon-edit'></span> Edit</button> &nbsp"

and here is my code that I use to close the window when I click save

function CloseTheWindow() {
    $("#window").data("kendoWindow").close();
}

So for the life of me, I do not understand why I can get it to close on the first time it gets opened and not the second time that its opened.


Solution

  • You should use $("#window").data("kendoWindow").destroy(); instead of $("#window").empty(); This way kendo widget is destroyd. Otherwise, you just clean only html element.

    Refer to how Destroy Widgets