What Is ExtJS ExtJS 4+ Extensions Examples Tutorials


shrinkWrap in ExtJS 4 and 5 Containers

ExtJS Containers and Panels are typically sized by their parent container's layout. Traveling up the layout chain typically leads to a Viewport, which occupies the available screen space; i.e. (view in Sencha Fiddle):

sample viewport

Now what about those times when you want to use these beautiful panels as the actual content, rather than as holders of other content? In other words, how can we make the Panels size based on their content (rather than as dictated by their parent's layout)? The end result might look something like this:

sample panel shrinkWrap

Read on to find out how its done and what caveats exist...

When you try to use Panels or Containers without having a parent layout dictated (which can by done by either renderTo directly to the body or by being a child of a Container without a layout set), they behave just like you would expect a normal div to behave: the height is sized based on the content and the width is expanded to fill up the available space provided by the parent DOM element. Here's what a Panel and a Container (with "cornflowerblue" background) would look like (view in Sencha Fiddle):

no shrinkwrap panel and container

The setting that will enable us to shrink-wrap the width is called (surprise) shrinkWrap. Do take the time to review its documentation as multiple settings are available (though most of the time you would just set it to "true"): http://docs.sencha.com/extjs/5.0.0/apidocs/#!/api/Ext.Component-cfg-shrinkWrap

Here is an example of using this setting with the Panel and Container shown above (view in Sencha Fiddle):

shrinkwrap panel and container

Note that the "cornflowerblue" Container did not react to the setting like the Panel did. While I consider this a bug, from talking to the framework engineers this is "by design" (with a technical explanation that was beyond me), so I wouldn't count on it changing anytime soon. The fix is rather straightforward though - just add "display: inline-block" to the style, while still keeping the shrinkWrap true set (view in Sencha Fiddle):

shrinkwrap container fix

VN:F [1.9.22_1171]
Rating: 9.3/10 (6 votes cast)
shrinkWrap in ExtJS 4 and 5 Containers, 9.3 out of 10 based on 6 ratings
Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

* Copy This Password *

* Type Or Paste Password Here *

No trackbacks yet.