我对 Flex 中的 AdvancedDataGrid 有疑问。我有一个带有可绑定 ArrayCollection 作为 DataProvider 的 AdvancedDataGrid。当我设置 ArrayCollection(通过单击按钮 1)时,AdvancedDataGrid 将代表 4 列。
之后我单击按钮 2。在这种情况下,AdvancedDataGrid 仍然显示 4 列而不是预期的 3 列。
方案 2
首先单击 Button2 -> AdvancedDataGrid 显示 3 列单击 Button1 -> AdvancedDataGrid 仍显示 3 列而不是预期的 4 列
如何告诉 AdvancedDataGrid 调整列数?
片段:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]
private var dataProv:ArrayCollection;
protected function button1_clickHandler(event:MouseEvent):void {
dataProv = new ArrayCollection([
{country:"USA", year2004:3.5, year2005:4.2, year2006:3.7},
{country:"UK", year2004:1.7, year2005:3.1, year2006:3.6},
{country:"Canada", year2004:2.8, year2005:2.9, year2006:3.4},
{country:"Japan", year2004:2.6, year2005:2.3, year2006:2.8},
{country:"France", year2004:1.4, year2005:2.1, year2006:2.6},
{country:"Brazil", year2004:2.6, year2005:4.9, year2006:4.4},
{country:"Russia", year2004:6.4, year2005:7.2, year2006:6.7},
{country:"India", year2004:8.0, year2005:7.1, year2006:6.6},
{country:"China", year2004:9.9, year2005:10.1, year2006:10.6}
]);
adg.validateNow();
adg.dataProvider.refresh();
}
protected function button2_clickHandler(event:MouseEvent):void{
dataProv = new ArrayCollection([
{country:"USA", year2004:3.5, year2005:4.2},
{country:"UK", year2004:1.7, year2005:3.1},
{country:"Canada", year2004:2.8, year2005:2.9},
{country:"Japan", year2004:2.6, year2005:2.3},
{country:"France", year2004:1.4, year2005:2.1},
{country:"Brazil", year2004:2.6, year2005:4.9},
{country:"Russia", year2004:6.4, year2005:7.2},
{country:"India", year2004:8.0, year2005:7.1},
{country:"China", year2004:9.9, year2005:10.1}
]);
adg.validateNow();
adg.dataProvider.refresh();
}
]]>
</mx:Script>
<mx:HBox width="100%" height="100%">
<mx:AdvancedDataGrid
id="adg"
width="100%"
height="100%"
dataProvider="{dataProv}"/>
<mx:Button label="change" click="button1_clickHandler(event)"/>
<mx:Button label="changeBack" click="button2_clickHandler(event)"/>
</mx:HBox>
</mx:Application>