Under My Palapa

Jason Young’s geek blog

Constraining ExtJs Floating Windows

with 2 comments

There are plenty of examples of creating floating windows with ExtJs. However, they all allow the window to be dragged wherever the user chooses. ExtJs supports a ‘constrain’ property on the window. If you just set this to true, then the user cannot drag the window outside of the browser viewport.

However, what if you want to be fancier, and constrain it inside of some other container? It seems obvious, but finding the answer is difficult. People on the ExtJs forums have posted this question, but the responses are generally a step away from being the real answer.

The answer is the renderTo config property, which you should point to the body property of the container. The forum responses generally indicate this, but they fail to mention the body property. This is what works for panels, I haven’t looked at all the other containers. But I have a feeling the concept would still apply.

var myPanel = new Ext.Panel({
    ...
});
var testWin = new Ext.Window({
    title: 'Test',
    width: 300,
    height: 300,
    renderTo: myPanel.body,
    constrain: true,
});
testWin.show();

Written by jaydfwtx

September 8, 2008 at 9:15 pm

Posted in extjs, web

Tagged with

2 Responses

Subscribe to comments with RSS.

  1. Thanks for the post and hopefully it helps someone else out learning Ext. We will update the documentation to be more explicit. When constraining an Ext.Window you must render it to some Element/HTMLElement. Panel has 3 Elements which it is composed of header, footer and body. It also has a container element which wraps around those other 3 elements. You can retrieve a reference to that container element with myPanel.getEl().

    Aaron Conran

    September 10, 2008 at 2:59 am

  2. Thanks for the response here on my blog, that was completely unexpected! :)

    jaydfwtx

    September 10, 2008 at 3:10 pm


Leave a Reply