AdvancedDataGridはキャンバス内の唯一のものですか?
AdvancedDataGridのサイズを完全な高さと幅に設定し、Canvasにスクロールを処理させます。
キャンバスで、updateDisplayListメソッドをオーバーライドし、次のようにします。
protected function updateDisplayList(unscaledWidth: Number, unscaledHeight: Number):void{
super.updateDisplayList, unscaledHeight);
this.myAdvancedDataGrid.setActualSize(this.myAdvancedDataGrid.measuredHeight, this.myAdvancedDataGrid.measuredWidth );
}
このように、AdvancedDataGridにはスクロールバーがないはずです。ただし、下または右に伸びすぎると、スクロールバーがキャンバスに表示されます。
FlexCoordinateSystemを読むことでメリットが得られる場合があります。AdvancedDataGridは「コンテンツ」であり、Canvasはローカルです。
私の提案をデモするために、完全に実行されているコードサンプルを追加しています。
これは、AdvancedDataGridが内部にあるキャンバスコンポーネントです:com.flextras.stackOverflow.CanvasWithGrid
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
super.updateDisplayList(unscaledWidth, unscaledHeight);
this.myADG.setActualSize(this.myADG.measuredWidth, this.myADG.measuredWidth );
}
[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}
]);
]]>
</fx:Script>
<mx:AdvancedDataGrid id="myADG"
initialize="gc.refresh();"> <!-- width="100%" height="100%" -->
<mx:dataProvider>
<mx:GroupingCollection id="gc" source="{dpFlat}">
<mx:grouping>
<mx:Grouping>
<mx:GroupingField name="Region"/>
<mx:GroupingField name="Territory"/>
</mx:Grouping>
</mx:grouping>
</mx:GroupingCollection>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Region"/>
<mx:AdvancedDataGridColumn dataField="Territory"/>
<mx:AdvancedDataGridColumn dataField="Territory_Rep"
headerText="Territory Rep"/>
<mx:AdvancedDataGridColumn dataField="Actual"/>
<mx:AdvancedDataGridColumn dataField="Estimate"/>
</mx:columns>
</mx:AdvancedDataGrid>
</mx:Canvas>
これはメインのアプリケーションファイルです。
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:stackOverflow="com.flextras.stackOverflow.*">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<stackOverflow:CanvasWithGrid width="200" height="200" />
</s:Application>