Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo UI Window to center after a refresh of large content

Using MVC 4 I add a blank window and hide it. On a button click I call this javascript to get content and center the window:

        var win = $("#myWindow").data("kendoWindow");
        win.content("Loading...");
        win.refresh({
            url: "@Url.Action("MyAction", "MyController")",
            data: { userloginid: "AAA" }
        });
        win.center();
        win.open();

The content is larger than a default window so the win.center() calculation is off, putting the window too far down.

How do I get the window to center based on the content it got via the refresh() command.

like image 844
Ian Vink Avatar asked Dec 27 '22 06:12

Ian Vink


1 Answers

The problem seems to be, that you center the window, and than, some time after that, the new content is finished loading.

In other words: The center is called before the window get's its new size through the loaded content.

To prevent this, you should bind to the refresh event of the window, and center in that.

Something along the lines (beware: only register this event once):

var win = $("#myWindow").data("kendoWindow");
win.bind("refresh", function() {
    win.center();
    win.open();
});
like image 117
Shion Avatar answered Dec 28 '22 20:12

Shion