开发者

Gridpanel auto resize on window resize

开发者 https://www.devze.com 2022-12-24 11:17 出处:网络
I\'m using the array-grid extjs example to try and fit a gridpanel into a container window. The problem is on resizing the conta开发者_如何学编程iner window, the gridpanel doesn\'t automatically fit t

I'm using the array-grid extjs example to try and fit a gridpanel into a container window. The problem is on resizing the conta开发者_如何学编程iner window, the gridpanel doesn't automatically fit the new size. As I understand it that's how it's supposed to work.

Here's the link to the example: http://www.extjs.com/deploy/dev/examples/grid/array-grid.html

What I've done is changed the following..

// Added to gridpanel config
layout: 'fit',
viewConfig: {
    forceFit: true
}

// Window container
var gridWindow = new Ext.Window({
    items: [
        grid
    ]
});

// Instead of grid.render, use gridWindow.show();
gridWindow.show();

Gridpanel auto resize on window resize


layout: 'fit',

should go into the gridWindow configuration! The layout manager arranges the children of a panel, but the grid is the child.


I'm using the following workaround:

Ext.onReady(function () {
    var grid = ... //define your grid here

    Ext.EventManager.onWindowResize(function () {
        grid.setSize(undefined, undefined);
    });
});

Extjs v4.0.7


I solved this by wrapping my gridpanel into an Ext.Panel, with a layout property set to 'fit'. The grid panel (with a viewConfig also containing forceFit: 'true' now is resized automatically when the window is resized


I think you need to use EventManager class. Please read it in following blog


Using ExtJS 6, this is what worked for me (doesn't need a Ext.Viewport as parent container):

var grid = //...

Ext.on('resize', function(w, h){
  grid.updateLayout();
});
0

精彩评论

暂无评论...
验证码 换一张
取 消