views:

1074

answers:

3

I can't figure out how to tell the accordioncontainer to set height of its accordion pane to auto so that the height of the pane is dynamic depending on its content.

In the following code I am adding two panes to an accordioncontainer. One has height of 10px and another has 90px but in both cases the height of the accordion pane is calculated to 10px. Looks like its always taking the height of the first one.

var accordionContainer = new dijit.layout.AccordionContainer({'id':'accContainer'}).placeAt("test");
var accordPane = new dijit.layout.ContentPane({"title": "test", "content":"<div style='height:10px'>sdfsdfsdf</div&gt;"});
var accordPane2 = new dijit.layout.ContentPane({"title": "test1", "content":"<div style='height:90px'>sdfsdfsdf</div>"});

accordionContainer.addChild(accordPane);
accordionContainer.addChild(accordPane2, 1);
accordPane.startup();
accordPane2.startup();
accordionContainer.startup();
accordionContainer.selectChild(accordPane2);

I am using dojo 1.3.2

A: 

try setting the dimensions on the Accordion Container itself to a size that is big enough to hold your content plus the necessary title panes, e.g.

#accContainer{
  height: 120px;
  width: 200px;
}

The startup() call on the container should start up the child panes for you.

peller
Thank you for your response but the height of my Accordion Container is dynamic as I won't know till runtime how many panes will be added to the the container.
pacman
+2  A: 

It is not currently possible. I wrote a blog / sample code to explain why and how to generate a group of TitlePane's that expand to their natural height (rather than the height of the container for the AccordionContainer):

http://www.sitepen.com/blog/2008/10/21/quick-fixes-and-dojo-support/

It requires making a single TitleGroup widget (custom, code in blog), and placing TitlePane's inside. Each behave mostly like an AccordionPane (with title="" attributes, href="" loading capabilities, etc) and delegates title clicks to manage the open/closed state of siblings.

dante
Thank you dante. Using title panes like you describe in your blog is probably the right thing to do, but due to time constraints I opted to extend the AccordionContainer widget and overrode its _getTargetHeight function and return 'auto' instead of the actual height. Please look at my solution below and comment if you see any side effect of doing this. Thanks.
pacman
If it works for you, good deal. The only caveat here would be that the method _getTargetHeight is a "private" method (denoted by the underscore) and _could_ potentially change in the future. Only the public APIs _always_ stay in place with deprecation policy. Not saying that it will change, just that Dijit is allowed to change those. There is a potential you would need to adjust your patch for future versions of Dojo/Dijit to accomodate the behavior. (or it may become a feature and the function may be redundant, who knows, it is "private" :) )
dante
+1  A: 

I Overrode the _getTargetHeight function of dijit.layout.AccordionContainer and always return 'auto' for height. Animation of sliding panes won't work correctly but its not that noticeable.

_getTargetHeight: function(/* Node */ node){
// summary:
//For the given node, returns the height that should be
//set to achieve our vertical space (subtract any padding
//we may have).
//This is used by the animations.

//var cs = dojo.getComputedStyle(node);
//return Math.max(this._verticalSpace - dojo._getPadBorderExtents(node, cs).h, 0);
return 'auto';
}
pacman