Thursday, June 7, 2012

How to Open a Telerik MVC Window Element in Javascipt?

Telerik Window can be managed from javascript function easily. You can check possible function names and descriptions here.

There are different ways to open a window in javascript but important one is to open as centered. Lets assume that we created a window via javascript.


    var windowElement = $.telerik.window.create({
        title: "...",
        html: "<p>I'm a window...</p>"
        contentUrl: "",
        actions: ["Maximize", "Close"],
        modal: true,
        width: 500,
        height: 500,
        resizable: false,
        draggable: true,
        scrollable: false,
        onClose: function () { }
    });

You can open it by just the following line :

    windowElement.center().open();

This will open the window but not centered surprisingly. You will have to get .data element first and then call the open and center functions.

    var window = $(windowElement).data('tWindow');
    window.center().open();


Above code will allow you successfully open a centered window.


Hope it helps.
P.S : If there is any typing or coding mistakes let me know. See you later.

No comments:

Post a Comment