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
2 个解决方案
#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:
DataGrid的高度由其rowCount属性控制。如果您希望DataGrid始终足够高以显示所有包含的元素(例如,将其包装在Scroller中以处理DataGrid对于可用空间而言太大的情况,而不是让DataGrid本身滚动),只需将其绑定到数据源的适当属性:
<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.
至于从自定义DataGrid实现到父对象的通信,您要做的是广播一个事件,指示高度应该更改,并附加一些值 - 可能是行数或新高度 - 事件。
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).
在学习了Flex中事件广播的基础知识之后,我意识到它们过于复杂并学习了Swiz框架,这使得事件广播和处理变得尽可能简单(在其他几个很棒的东西中)。
#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:
DataGrid的高度由其rowCount属性控制。如果您希望DataGrid始终足够高以显示所有包含的元素(例如,将其包装在Scroller中以处理DataGrid对于可用空间而言太大的情况,而不是让DataGrid本身滚动),只需将其绑定到数据源的适当属性:
<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.
至于从自定义DataGrid实现到父对象的通信,您要做的是广播一个事件,指示高度应该更改,并附加一些值 - 可能是行数或新高度 - 事件。
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).
在学习了Flex中事件广播的基础知识之后,我意识到它们过于复杂并学习了Swiz框架,这使得事件广播和处理变得尽可能简单(在其他几个很棒的东西中)。