<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="initDP();"
width="550"
height="400">
<mx:Script>
<![CDATA[
import mx.events.DataGridEvent;
import mx.collections.*;
// Declare storage variables and initialize the simple variables.
// The data provider collection.
private var myDPColl:ArrayCollection;
// The Sort object used to sort the collection.
[Bindable]
private var sortA:Sort;
// The sort fields used to determine the sort.
private var sortByInStock:SortField;
private var sortByArtist:SortField;
private var sortByAlbum:SortField;
private var sortByPrice:SortField;
// The data source that populates the collection.
private var myDP:Array=[{Artist: 'Pavement', Album: 'Slanted and Enchanted', Price: 11.99, InStock: true}, {Artist: 'Pavement', Album: 'Crooked Rain, Crooked Rain', Price: 10.99, InStock: false}, {Artist: 'Pavement', Album: 'Wowee Zowee', Price: 12.99, InStock: true}, {Artist: 'Asphalt', Album: 'Brighten the Corners', Price: 11.99, InStock: false}, {Artist: 'Asphalt', Album: 'Terror Twilight', Price: 11.99, InStock: true}, {Artist: 'Asphalt', Album: 'Buildings Meet the Sky', Price: 14.99, InStock: true}, {Artist: 'Other', Album: 'Other', Price: 5.99, InStock: true}];
//Initialize the DataGrid control with sorted data.
private function initDP():void
{
//Create an ArrayCollection backed by the myDP array of data.
myDPColl=new ArrayCollection(myDP);
//Create a Sort object to sort the ArrrayCollection.
sortA=new Sort();
//Initialize SortField objects for all valid sort fields:
// A true second parameter specifies a case-insensitive sort.
// A true third parameter specifies descending sort order.
// A true fourth parameter specifies a numeric sort.
sortByInStock=new SortField("InStock", true, true);
sortByArtist=new SortField("Artist", true);
sortByAlbum=new SortField("Album", true);
sortByPrice=new SortField("Price", true, false, true);
// Sort the grid using the InStock, Artist, and Album fields.
sortA.fields=[sortByInStock, sortByArtist, sortByAlbum];
myDPColl.sort=sortA;
// Refresh the collection view to show the sort.
myDPColl.refresh();
// Initial display of sort fields
tSort0.text="First Sort Field: InStock";
tSort1.text="Second Sort Field: Artist";
tSort2.text="Third Sort Field: Album";
// Set the ArrayCollection as the DataGrid data provider.
myGrid.dataProvider=myDPColl;
// Set the DataGrid row count to the array length,
// plus one for the header.
myGrid.rowCount=myDPColl.length + 1;
}
// Re-sort the DataGrid control when the user clicks a header.
private function headRelEvt(event:DataGridEvent):void
{
// The new third priority was the old second priority.
sortA.fields[2]=sortA.fields[1];
tSort2.text="Third Sort Field: " + sortA.fields[2].name;
// The new second priority was the old first priority.
sortA.fields[1]=sortA.fields[0];
tSort1.text="Second Sort Field: " + sortA.fields[1].name;
// The clicked column determines the new first priority.
if (event.columnIndex == 0)
{
sortByArtist.descending=!sortByArtist.descending;
sortA.fields[0]=sortByArtist;
}
else if (event.columnIndex == 1)
{
sortByAlbum.descending=!sortByAlbum.descending;
sortA.fields[0]=sortByAlbum;
}
else if (event.columnIndex == 2)
{
sortByPrice.descending=!sortByPrice.descending;
sortA.fields[0]=sortByPrice;
}
else
{
sortA.fields[0]=sortByInStock;
}
tSort0.text="First Sort Field: " + sortA.fields[0].name;
// Apply the updated sort fields and re-sort.
myDPColl.sort=sortA;
// Refresh the collection to show the sort in the grid.
myDPColl.refresh();
// Prevent the DataGrid from doing a default column sort.
event.preventDefault();
}
]]>
</mx:Script>
<!-- The Data Grid control.
By default the grid and its columns can be sorted by clicking.
The headerRelease event handler overrides the default sort
behavior. -->
<mx:DataGrid id="myGrid"
width="100%"
headerRelease="headRelEvt(event);">
<mx:columns>
<mx:DataGridColumn minWidth="120"
dataField="Artist"/>
<mx:DataGridColumn minWidth="200"
dataField="Album"/>
<mx:DataGridColumn width="75"
dataField="Price"/>
<mx:DataGridColumn width="75"
dataField="InStock"
headerText="In Stock"/>
</mx:columns>
</mx:DataGrid>
<mx:VBox>
<mx:Label id="tSort0"
text="First Sort Field: "/>
<mx:Label id="tSort1"
text="Second Sort Field: "/>
<mx:Label id="tSort2"
text="Third Sort Field: "/>
</mx:VBox>
</mx:Application>
分享到:
相关推荐
flex DataGrid中文字符排序类 用法见 http://blog.sina.com.cn/s/blog_5fc933730100iign.html
DataGrid中的排序列怎么设
flex 自定义 datagrid 列头带组合框进行过滤
此程序用于设置 flex DataGrid 的某列的位置固定,不论怎么拖动列的位置都不会变
Flex dataGrid 全选、反选 checkBox 不是很完善,但很有借鉴意义
flex datagrid 实现合计功能控件包 带源码,demo fxp是flex4的工程文件,导入到工作空间即可 直接导入项目即可。 更多访问我的blog www.dplayer.net
FLEX的datagrid合计、平均值,很好的例子代码拿来就可以用
flex datagrid 改变指定行的背景颜色,可直接使用
这个分页只与后台交互一次,然后将获得的集合在前台进行分页显示。
DataGrid自定义列标题 DataGrid自定义列标题 DataGrid自定义列标题 DataGrid自定义列标题 DataGrid自定义列标题
flex datagrid资料,下载的别人的,想弄点分数啊
行中实现勾选与下拉列表功能
NULL 博文链接:https://lqw.iteye.com/blog/537409
在FLEX4中开发带有过滤功能的DATAGRID组件
本实例是在datagrid里插入多列Checkbox的应用,不存在拖动下拉条混乱问题,里面代码很简单,但希望可以帮到你。
成功的实现了,datagrid中嵌套checkbox实现全选的功能。分享代码供大家分享。项目为flex3。
NULL 博文链接:https://windmark.iteye.com/blog/1716422
flex Datagrid checkbox全选 Datagrid
flex 通过读取xml文件 实现动态DataGrid数据列表
可以通过简单的一个标签实现一个表的checkbox功能,当然我才学了不到一个星期,可以在原来的基础上进行扩展,希望交流下我的邮箱是llaysz@163.com,如果大家把它变强大了记得给我发一份谢谢了