Dynamically resized Datagrid
One of my biggest pet peeves of the datagrid control in Flex is that it gives you a set number of rows when it first initializes. Sure, you can adjust the height, but there is not setting for it to be as tall as the data. So how do you set the height to be where you want it?
dg.height=(dg.dataProvider.length*dg.rowHeight)+dg.headerHeight+3; dg.scrollToIndex(0);
This code makes three assumptions:
- You've got a datagrid named "dg" with a dataprovider
- You've got your borderthickness set to 1 on the datagrid. That's what the "+3" is for.... I'm sure we could dive into figuring out how to really fully dynamically create the resizer, but for most of us it's okay like that.
- VerticalScrollPolicy is set to "off"
<mx:Resize duration="200" id="resizeDGEffect"/>
One more thing, resizeEffect={resizeDGEffect}" on the datagrid you made. The last step is to add an event listener to your dataprovider and call a resize function with the contents of the code above.
Check out the example and right click to view the source!

0 Comments:
Post a Comment
<< Home