ExtJs Window Resize on Browser Resize

In this blog, I will explain how to resize all the modal window on ExtJs on browser resize. In one of my recent project, I had a requirement to resize all the modal windows open at the same time on browser resize.  Following is the solution.

You must have some main view of app which should be rendered first when app starts. You have to add render event of that view as follow.

this.control({
‘mainView’: {
render: this.onMainViewRender
        }
});

Now add the following function in your controller file.

onMainViewRender: function() {
Ext.EventManager.onWindowResize( this.onBrowserResize, this );
}

Above function binds the browser resize event and add a callback function to it. Following is the function definition of onBrowserResize

onBrowserResize: function( width, height ) {

Ext.WindowManager.each( function( window ) {

if( !window.isXType( ‘window’ ) )
                return;                      
if( height < 600 ) {
                                window.maxHeight = height – 30;
                                window.doLayout();
                                window.center();
                        } else {
                                window.maxHeight = 600;
                                window.doLayout();
                                window.center();
                        }
                });
}

It might be possible that we have some message box open at that time so we have to ignore it. That’w why we are checking the window xtype. Here we are setting maxHeight of window. 600 is just the example here. You can change it with your own preference. Else loop is to restore window to it’s original height and width if browser is resized to bigger height and width than window.

Hope this helps you.

This entry was posted in Browser Resize, ExtJs, Window Resize on by .

About Hiren Dave

Hiren Dave is a software engineer, blogger and consultant with over 9 years of professional experience. He writes code in number of languages. Hiren has a passion for developing web apps, mobile apps and writing books and blog articles about programming. He has a solid experience of startups as he manages products for few startups. He is also passionate about researching and learning new technologies and trends. He has also authored a book Instant Sencha Touch, published by Packt and creator of Video Course "Beginning Laravel" for Packt

Leave a Reply

Your email address will not be published. Required fields are marked *