flex datagrid - making grid height dynamic and com

2019-07-07 18:46发布

问题:

HI,

i want to build a datagrid which will have a dynamic height value because the number of rows will always be different. I also want to communicate the height back to the component holiding it so that it also grows with the datagrid. Can anyone help me out on the best way to create such a dynamic datagrid.

Thanks

回答1:

The DataGrid's height is controlled by its rowCount property. If you want your DataGrid to always be exactly high enough to show all the contained elements (and, for example, wrap it inside a Scroller to handle the situation where the DataGrid is too big for the available space, rather than having the DataGrid itself scroll), simply bind it to an appropriate property of your data source:

<mx:DataGrid dataProvider="{myData}" rowCount="{myData.length}"/>
<fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;

        protected var myData:ArrayCollection;
    ]]>
</fx:Script>


回答2:

Can you be more specific? Are you saying you don't want the datagrid to scroll? What about cases where the number of rows exceeds what can be seen on screen? -- Once you answer those questions, I can edit this to be a more specific answer.

As for communicating from your custom DataGrid implementation up to the parent object, what you want to do is broadcast an event indicating that the height should change, and attach some value -- the number of rows or the new height, probably -- to that event.

After learning the basics of event broadcasting in Flex, I realized they were way overcomplicated and learned the Swiz framework, which makes event Broadcasting and Handling about as simple as they could possibly be (among several other awesome things).