3

I've got a fiddle of a base layout I'm trying to add responsive configurations to.

My goal is to use a border layout where the navigation can change between the western region and the northern region depending on the window size and the layout config can switch between vertical and horizontal so that when the region is west the buttons are grouped vertically and when the region is north the buttons are grouped horizontally.

I know that by default, the layout type cannot be changed at runtime, but I found this forum thread where a user points out that if you use the box layout type (the parent of vbox and hbox) you can update the vertical config to change the grouping at runtime.

The fiddle I linked above is my attempt at prototyping that concept out.

The problem I'm running into is that the responsiveConfig cannot find the setters for the particular properties that I'm trying to change, and it's not just for the vertical config. Config items that I know have setters and I have seen work before in the responsiveConfig are not working as well:

enter image description here

Ext.layout.container.Box definitely has a setPack method.

Am I mis-configured somehow?

Guilherme Lopes
  • 4,688
  • 1
  • 19
  • 42
Chris Schmitz
  • 20,160
  • 30
  • 81
  • 137

3 Answers3

4

I posted to the thread in sencha's forums where the technique I was trying was described. The poster who answered the question originally answered my post with an updated fiddle showing the correct implementation.

I've added the responsive box implementation as well as the region switching into my fiddle.

Here's the responsive sections needed:

plugins: 'responsive',
responsiveConfig:{
    wide:{
        layout:{
            type: 'box',
            vertical: true,
            pack:'start'
        },
        region: 'west'
    },
    tall:{
        layout:{
            type: 'box',
            vertical: false,
            pack: 'center'
        },
        region: 'north'
    }

I think the important part to know here (and what was tripping me up) is that you have to include the type: 'box' in the layout config for the responsiveConfig property because responsiveConfig is not firing each individual setter for the layout (type, vertical, and pack), it's firing the overall layout setter method. If you don't include the type config in the object you give the layout config, it uses the default type which is 'auto'.

This is why in the screenshot I included in the original post the error messages in the javascript console where referring to Ext.layout.container.Auto and not Ext.layout.container.Box. The error message was right, Ext.layout.container.Auto doesn't have a setPack method.

Chris Schmitz
  • 20,160
  • 30
  • 81
  • 137
1

Changing layouts at runtime is not currently supported. There is a feature request for it here: https://www.sencha.com/forum/showthread.php?294082

Fiddle with a workaround: https://fiddle.sencha.com/#fiddle/dqj

Tarabass
  • 3,132
  • 2
  • 17
  • 35
  • Cool, thanks for the head's up re: the feature request and the workaround fiddle. It's not going to work in my case because a number of the nav buttons are going to be non-tab items and the look has to be consistent so a tabpanel isn't an option :/ – Chris Schmitz Jul 22 '15 at 20:46
0

The error is complaining about auto layout having no setter for pack. This tells me the layout is indeed being set during runtime, according to the value specified in the responsive layout config. Since there is none defined, just the vertical and pack, config, the layout type is interpreted as auto. Small changes in your fiddle, defining the layout type as below:

responsiveConfig:{
    wide:{
        layout:{
            type : 'vbox',
            pack:'start'
        },
        bodyStyle:{'background-color': 'orange'}
    },
    tall:{
        layout:{
            type : 'hbox',
            pack: 'center'
        },
        bodyStyle:{'background-color': 'purple'}
    }
},

And your error was gone.

Elias Medeiros
  • 395
  • 3
  • 10
  • It does suppress the error, but it doesn't achieve the functionality; the buttons do no switch their grouping type. The [sencha documentation on Ext.Panel](http://docs.sencha.com/extjs/6.0/6.0.0-classic/#!/api/Ext.panel.Panel-method-setLayout) points out that the layout type cannot be changed at runtime. That's why I was attempting this approach with changing the vertical property since it can be set at runtime. – Chris Schmitz Jul 22 '15 at 19:40