Chinaunix首页 | 论坛 | 博客
  • 博客访问: 30468344
  • 博文数量: 708
  • 博客积分: 12163
  • 博客等级: 上将
  • 技术积分: 8240
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-04 20:59
文章分类

全部博文(708)

分类: 系统运维

2008-08-27 18:29:02

对分层数据进行列分组

和扁平数据一样,您使用分层数据进行列分组,以下例子修改自“为导航树创建单独的列“章节中的示例以将Actual和Estimates列归组到Revenues组列中:

 version="1.0" encoding="utf-8"?>
xmlns:mx="">
>

import mx.collections.ArrayCollection;
include "SimpleHierarchicalData.as";
]]>

>

width="100%" height="100%">
>

source="{dpHierarchy}"/>
>

>
dataField="Region"/>
dataField="Territory_Rep"
headerText="Territory Rep"/>

headerText="Revenues">
dataField="Actual"/>
dataField="Estimate"/>
>

>

>

>

上面的列分组示例中并没有为AdvancedDataGridColumnGroup类指定数据字段,但是,AdvancedDataGridColumnGroup类就是被设计用于和分层数据一起工作的。因此,如果您给AdvancedDataGridColumnGroup类指定一个数据字段的话,它将自动给该数据字段的子字段创建一个列分组。

在下面示例中,HierarchicalDataForGroupedColumns.as文件定义了一个分层数据,设置Revenues字段包含俩个子字段,Actual 和Estimate:

[Bindable]
private var dpHierarchy:ArrayCollection = new ArrayCollection([
{Region:"Southwest", Territory:"Arizona",
Territory_Rep:"Barbara Jennings",
Revenues:{Actual:38865, Estimate:40000}},
{Region:"Southwest", Territory:"Arizona",
Territory_Rep:"Dana Binn",
Revenues:{Actual:29885, Estimate:30000}},
{Region:"Southwest", Territory:"Central California",
Territory_Rep:"Joe Smith",
Revenues:{Actual:29134, Estimate:30000}},
{Region:"Southwest", Territory:"Nevada",
Territory_Rep:"Bethany Pittman",
Revenues:{Actual:52888, Estimate:45000}},
{Region:"Southwest", Territory:"Northern California",
Territory_Rep:"Lauren Ipsum",
Revenues:{Actual:38805, Estimate:40000}},
{Region:"Southwest", Territory:"Northern California",
Territory_Rep:"T.R. Smith",
Revenues:{Actual:55498, Estimate:40000}},
{Region:"Southwest", Territory:"Southern California",
Territory_Rep:"Alice Treu",
Revenues:{Actual:44985, Estimate:45000}},
{Region:"Southwest", Territory:"Southern California",
Territory_Rep:"Jane Grove",
Revenues:{Actual:44913, Estimate:45000}}
]);

下面示例使用该数据并且指定Revenues字段为AdvancedDataGridColumnGroup.dataField属性的值,其输出如下:

以下是实现代码:

 version="1.0" encoding="utf-8"?>
xmlns:mx="">
>

import mx.collections.ArrayCollection;
include "HierarchicalDataForGroupedColumns.as";
]]>

>

id="myADG"
width="100%" height="100%"
defaultLeafIcon="{null}">

>

source="{dpHierarchy}"/>
>

>
dataField="Region"/>
dataField="Territory"/>
dataField="Territory_Rep"
headerText="Territory Rep"/>

dataField="Revenues">
dataField="Actual"/>
dataField="Estimate"/>
>

>

>

>

在ActionScript中创建分组

前面章节的示例我们使用的是MXML来创建分组,然而,您可能想让用户实时定义分组。以下示例通过事件处理器在ActionScript中创建分组:

"1.0" encoding="utf-8"?>
"" layout="vertical">

[CDATA[
import mx.collections.GroupingField;
import mx.collections.Grouping;
import mx.collections.GroupingCollection;
import mx.collections.ArrayCollection;
include "SimpleFlatData.as";
[Bindable]
public var myGColl:GroupingCollection = new GroupingCollection();
private var myGrp:Grouping = new Grouping();
private function initDG():void {
// Initialize the GroupingCollection instance.
myGColl.source = dpFlat;
// The Grouping instance defines the grouping fields
// in the collection, and the order of the groups
// in the hierarchy.
myGrp.fields =
[new GroupingField("Region"), new GroupingField("Territory")];
// The grouping property contains a Grouping instance.
myGColl.grouping = myGrp;
// Specify the GroupedCollection as the data provider for
// the AdvancedDataGrid control.
myADG.dataProvider=myGColl;
// Refresh the display.
myGColl.refresh();
}
]]>

"myADG"
width="100%" height="100%"
creationComplete="initDG();">

"Region"/>
"Territory"/>
"Territory_Rep"
headerText="Territory Rep"/>
"Actual"/>
"Estimate"/>


阅读(2349) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~