我正在使用 flex 创建嵌套数据网格,每个级别都有不同的列(请参阅屏幕截图)。但它为每一列呈现新的数据网格。
这是我的 mxml
<?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">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var dpHierarchy:ArrayCollection = new ArrayCollection([
{Country:"INDIA", Category:"Developing Country" ,Population:100000000,
children: [
{State:"Andhra", Language:"Telugu", SoilColor:"Red",
children:[
{District:"GUNTUR", HeadQuaters:388865, Crops:"Tobacco"},
{District:"Vijayawada", HeadQuaters:388865, Crops:"rice"}
] },
{State:"Karnataka", Language:"Kannada", SoilColor:"Black",
children:[
{District:"Mysore", HeadQuaters:388865, Crops:"Mirchi"},
{District:"Mandya", HeadQuaters:388865, Crops:"Vegetables"}
] }
] },
{Country:"KOREA", Category:"UnDeveloping Country", Population:100000000,
children:[
{State:"fgff", Language:"fggff", SoilColor:"Red",
children: [
{District:"fgdfgfg", HeadQuaters:388865, Crops:"Tobacco"},
{District:"gfgdfgfg", HeadQuaters:388865, Crops:"rice"}
] },
{State:"fgfgdfg", Language:"gdfgdfg", SoilColor:"Black",
children:[
{District:"ggff", HeadQuaters:388865, Crops:"Mirchi"},
{District:"gfgfgfg", HeadQuaters:388865, Crops:"Vegetables"}
] }
] }
]);
]]>
</fx:Script>
<mx:AdvancedDataGrid width="100%" height="100%" variableRowHeight="true">
<mx:dataProvider>
<mx:HierarchicalData source="{dpHierarchy}"/>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Country" headerText="Country"/>
<mx:AdvancedDataGridColumn dataField="Category" headerText="Category"/>
<mx:AdvancedDataGridColumn dataField="Population" headerText="Population"/>
<mx:AdvancedDataGridColumn dataField="children" headerText="children"/>
</mx:columns>
<mx:rendererProviders>
<mx:AdvancedDataGridRendererProvider columnIndex="1" columnSpan="4" depth="2"
renderer="InnerGrid"/>
<mx:AdvancedDataGridRendererProvider columnIndex="2" columnSpan="3" depth="3"
renderer="InnerChildGrid"/>
</mx:rendererProviders>
</mx:AdvancedDataGrid>
</s:Application>
这是我的自定义渲染器 [InnerGrid.mxml]
<?xml version="1.0" encoding="utf-8"?>
<mx:AdvancedDataGrid 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[
override public function set data(value:Object):void {
this.dataProvider = value;
}
]]>
</fx:Script>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="State" headerText="State"/>
<mx:AdvancedDataGridColumn dataField="Language" headerText="Language"/>
<mx:AdvancedDataGridColumn dataField="SoilColor" headerText="SoilColor"/>
</mx:columns>
</mx:AdvancedDataGrid>
这是我的自定义渲染器 [InnerChildGrid.mxml]
<?xml version="1.0" encoding="utf-8"?>
<mx:AdvancedDataGrid 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[
override public function set data(ivalue:Object):void {
this.dataProvider = ivalue.Districts;
}
]]>
</fx:Script>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="District"/>
<mx:AdvancedDataGridColumn dataField="HeadQuaters"/>
<mx:AdvancedDataGridColumn dataField="Crops"/>
</mx:columns>
</mx:AdvancedDataGrid>