Closing a kendoui window with custom Close button within the window

旧街凉风 提交于 2019-12-03 05:31:14
Petur Subev

Basically you already know how to close the window - you need to do it with the close method of its API.

$("#window").data("kendoWindow").close();

But in order to attach the handler to the button inside of the view you need to wait until the content is loaded - you need to use the refresh event.

e.g.

$('#theWindowId').data().kendoWindow.bind('refresh',function(e){
    var win = this;
    $('#close').click(function(){
         win.close();
    })
})

In JavaScript - HTML window is an object that represents an open window in a browser. Try defining your window as something else.

$(document).ready(function () {
    var wnd = $("#window").data("kendoWindow");

    $("#open").click(function (e) {
        wnd.center();
        wnd.open();
    });

    $("#close").click(function(e) {
        wnd.close();
    });
});

there is an event in kendo ui for this it should be something like this

 $("#idofyourbutton").click(function () {
     $("#window").data("kendoWindow").close();
    });
Vinícius Rosa

In case of working with content loaded by ajax, the Petur Subev's answer is perfect! I´d like to give an example working with templates, that is more simple (whereas not all requests shoulb be by ajax). Consider the template below:

<script id="Template_Example1" type="text/kendo-tmpl">
<div class="i-contentWindow">
    <div>
        <a id="btn1" href="\#"><span class="k-icon k-i-cancel"></span>Button 1</a>
    </div>
</div>

And now, let´s load the template e call window close method:

function ExampleFn1(dataItem) {
    //create the template
    var template = kendo.template($("#Template_Example1").html());

    //create a kendo window to load content
    var kWindow = openKendoWindow({
        title: "Window Tests",
        iframe: false,
        resizable: false
    }).content(template(dataItem));

    // call window close from button inside template
    $("#btn1").click(function (e) {
        e.preventDefault();
        alert("btn1 on click!");
    });

    kWindow.open();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!