Ian Vink
Ian Vink

Reputation: 68810

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.

Upvotes: 4

Views: 6652

Answers (1)

Shion
Shion

Reputation: 1499

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();
});

Upvotes: 11

Related Questions