我们正在 flex 3 中开发一个高级数据网格,以便在调用特定状态时可以隐藏该数据网格中的列。
在做示例时,我们遇到了一个问题,我们的数据网格中有某些列,我们滚动到最后一列,然后现在我们隐藏了可见区域中的所有列。在此之后,所有列都消失了。在这里,我附上了快照。
单击隐藏列按钮后,高级数据网格变为
请在这个问题上帮助我。
注意:我们尝试在隐藏每一列时使用 validateNow()。但这给我们的项目编辑器带来了很多麻烦。
我的示例代码片段:
protected function button1_clickHandler(event:MouseEvent):void
{
myADG.columns[7].visible = false;
myADG.columns[8].visible = false;
myADG.columns[9].visible = false;
myADG.columns[10].visible = false;
}
我的示例代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.core.mx_internal;
use namespace mx_internal;
[Bindable]
private var dpFlat:ArrayCollection = new ArrayCollection([
{Region:"Southwest", Territory:"Arizona",
Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
{Region:"Southwest", Territory:"Arizona",
Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000},
{Region:"Southwest", Territory:"Central California",
Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000},
{Region:"Southwest", Territory:"Nevada",
Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000},
{Region:"Southwest", Territory:"Northern California",
Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
{Region:"Southwest", Territory:"Northern California",
Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000},
{Region:"Southwest", Territory:"Southern California",
Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},
{Region:"Southwest", Territory:"Southern California",
Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
]);
protected function button1_clickHandler(event:MouseEvent):void
{
myADG.columns[7].visible = false;
myADG.columns[8].visible = false;
myADG.columns[9].visible = false;
myADG.columns[10].visible = false;
}
]]>
</mx:Script>
<mx:Panel title="AdvancedDataGrid Control Example"
height="75%" width="75%" layout="horizontal"
paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
<mx:AdvancedDataGrid id="myADG"
width="50%" height="60%"
dataProvider="{dpFlat}" horizontalScrollPolicy="on" >
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Region" width="100" headerText="1"/>
<mx:AdvancedDataGridColumn dataField="Territory" width="100" headerText="2" visible="true"/>
<mx:AdvancedDataGridColumn dataField="Territory_Rep"
headerText="3" width="100" visible="true"/>
<mx:AdvancedDataGridColumn dataField="Actual" width="100" headerText="4" visible="true"/>
<mx:AdvancedDataGridColumn dataField="Estimate" width="100" headerText="5" visible="true"/>
<mx:AdvancedDataGridColumn dataField="Territory_Rep"
headerText="6" width="100" visible="true"/>
<mx:AdvancedDataGridColumn dataField="Actual" width="100" headerText="7"/>
<mx:AdvancedDataGridColumn dataField="Estimate" width="100" headerText="8"/>
<mx:AdvancedDataGridColumn dataField="Territory_Rep"
headerText="9" width="100"/>
<mx:AdvancedDataGridColumn dataField="Actual" width="100" headerText="10"/>
<mx:AdvancedDataGridColumn dataField="Estimate" width="100" headerText="11"/>
</mx:columns>
</mx:AdvancedDataGrid>
<mx:Button label="Hide Columns" click="button1_clickHandler(event)" />
</mx:Panel>
</mx:Application>