Flex4.6 DataGrid GridItemRenderer宣染器
本文转自:http://blog.sina.com.cn/s/blog_71848dcf01012ctl.html,稍作修改
<?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"
creationComplete="Init()">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.core.mx_internal;
[Bindable]
public var cloumnSelected:Boolean=false;//保存该列是否全选的属性(用户先点击全选后在手动的取消几行数据的选中状态时,这里的状态不会改变)
[Bindable]
public var headerSelected:Boolean=false;
public var selectItems:Array = new Array();//用户保存用户选中的数据
public function cleanSelectItems():void{
selectItems= new Array();
}
[Bindable]
public var dataArray:ArrayCollection = new ArrayCollection;
private function Init():void{
dataArray.addItem({dgSelected:false,name:'1.Christina Coenraets',phone:'555-219-2270',email:'ccoenraets@fictitious.com'});
dataArray.addItem({dgSelected:false,name:'2.Joanne Wall',phone:'555-219-2012',email:'jwall@fictitious.com'});
dataArray.addItem({dgSelected:false,name:'3.Maurice Smith',phone:'555-219-2012',email:'maurice@fictitious.com'});
dataArray.addItem({dgSelected:false,name:'4.Mary Jones',phone:'555-219-2000',email:'mjones@fictitious.com'});
dataArray.addItem({dgSelected:false,name:'5.God Win',phone:'555-219-2005',email:'godwin@fictitious.com'}); dataArray.addItem({dgSelected:false,name:'6.Christina Coenraets-2',phone:'555-219-2270',email:'ccoenraets@fictitious.com'});
dataArray.addItem({dgSelected:false,name:'7.Joanne Wall-2',phone:'555-219-2012',email:'jwall@fictitious.com'});
dataArray.addItem({dgSelected:false,name:'8.Maurice Smith-2',phone:'555-219-2012',email:'maurice@fictitious.com'});
dataArray.addItem({dgSelected:false,name:'9.Mary Jones-2',phone:'555-219-2000',email:'mjones@fictitious.com'});
dataArray.addItem({dgSelected:false,name:'10.God Win-2',phone:'555-219-2005',email:'godwin@fictitious.com'}); var str:String = "";
str = "as";
str = str + "aws";
} protected function btn_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
var items:Array = new Array(); var name2:String = "";
for(var i:int = 0; i<this.selectItems.length; i++){
// if(this.cloumnSelected){
// items = this.selectItems;
// var obj:Object = items[i];
// name = name + obj.name + " | ";
// }else{
//
// }
// Alert.show(name,"name"); var obj2:Object = this.selectItems[i];
name2 = name2 + obj2.name + " | ";
}
Alert.show(name2,"name2");
trace(name2);
} ]]>
</fx:Script>
<s:DataGrid id="dgUser" x="116" y="99" width="1016" height="328" dataProvider="{dataArray}">
<s:columns>
<s:ArrayList>
<s:GridColumn width="60" dataField="dgSelected" resizable="false" sortable="false">
<s:itemRenderer>
<fx:Component>
<s:GridItemRenderer>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import spark.components.DataGrid;
import spark.components.gridClasses.GridColumn;
private var currentData:Object; //保存当前一行值的对象
protected function checkbox1_changeHandler(event:Event):void
{
// TODO Auto-generated method stub
//Alert.show(rowIndex+"");
var dg:DataGrid=this.automationOwner as DataGrid;//获取DataGrid对象
var dgDataArr:ArrayCollection = dg.dataProvider as ArrayCollection;
var selectItems:Array=this.parentApplication.selectItems;
currentData=data;
currentData.dgSelected=cbx.selected; //根据是否选中的状态,更改数据源中选中的标记
var bool:Boolean=true;
if (cbx.selected)
{
selectItems.push(currentData);
this.parentApplication.selectItems = selectItems;
abc:for(var j:int=0;j<dgDataArr.length;j++){
var obj:Object=dgDataArr[j];
var dgSelected:Boolean=obj.dgSelected;
if (dgSelected == false)
{
bool=false;
break abc;
}
}
if (bool == true)
{
this.parentApplication.headerSelected=true;
this.parentApplication.cloumnSelected = true;
}
}else{
for (var i:int=0; i < selectItems.length; i++)
{
if (selectItems[i] == currentData)
{
selectItems.splice(i, 1)//当前行checkbox为false时,从selectItems删除当前行
}
}
if(selectItems.length==0){
this.parentApplication.cloumnSelected = false;
}
this.parentApplication.headerSelected=false;
}
}
]]>
</fx:Script>
<s:HGroup>
<s:Label width="10"/>
<s:CheckBox id="cbx" change="checkbox1_changeHandler(event)"
selected="{this.parentApplication.cloumnSelected}"/>
<s:Label width="10"/>
</s:HGroup>
</s:GridItemRenderer>
</fx:Component>
</s:itemRenderer>
<s:headerRenderer>
<fx:Component>
<s:GridItemRenderer>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import spark.components.DataGrid;
import spark.components.gridClasses.GridColumn;
protected function selectAll_clickHandler(event:MouseEvent):void
{
var dg:DataGrid=this.automationOwner as DataGrid;//获取DataGrid对象
var dgDataArr:ArrayCollection = dg.dataProvider as ArrayCollection;
//更改列的全选状态
// if(this.parentApplication.cloumnSelected){
// this.parentApplication.cloumnSelected = false;
// }else{
// this.parentApplication.cloumnSelected = true;
// }
if(selectAll.selected){
this.parentApplication.headerSelected=false;
this.parentApplication.cloumnSelected = false;
this.parentApplication.headerSelected=true;
this.parentApplication.cloumnSelected = true;
}else {
this.parentApplication.headerSelected=true;
this.parentApplication.cloumnSelected = true;
this.parentApplication.headerSelected=false;
this.parentApplication.cloumnSelected = false;
}
parentApplication.selectItems = new Array();//重新初始化用于保存选中列的对象
if(this.parentApplication.cloumnSelected){//如果为全部选中的化就将数据源赋值给column.selectItems,不是就不管他,上一步已经初始化为空
parentApplication.selectItems = (dg.dataProvider as ArrayCollection).toArray();
}
if(dgDataArr.length>0){
if(dgDataArr[0]!=""){
for(var i:int = 0; i < dgDataArr.length ; i++){
// Object(dgDataArr).dgSelected = this.parentApplication.cloumnSelected;//更改没一行的选中状态
Object(dgDataArr[i]).dgSelected = this.parentApplication.cloumnSelected;//更改没一行的选中状态
}
}
}
dgDataArr.refresh();//刷新数据源,达到强制更新页面显示效果的功能,防止在使用时没有在VO类中使用绑定而出现点击全选页面没有更改状态的错误
//Alert.show(this.parentApplication.DataGrid3.dataProvider.length);
}
]]>
</fx:Script>
<s:HGroup>
<s:Label paddingTop="5" text=" 全选 "/>
<s:CheckBox id="selectAll" click="selectAll_clickHandler(event)"
selected="{this.parentApplication.headerSelected}"/>
<s:Label width="10"/>
</s:HGroup>
</s:GridItemRenderer>
</fx:Component>
</s:headerRenderer>
</s:GridColumn>
<s:GridColumn dataField="name" headerText="姓名"/>
<s:GridColumn dataField="phone" headerText="电话"/>
<s:GridColumn dataField="email" headerText="邮件"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
<s:Button x="116" y="50" id="btn" label="button" click="btn_clickHandler(event)"/> </s:Application>
Flex4.6 DataGrid GridItemRenderer宣染器的更多相关文章
- Flex4/Flash开发在线音乐播放器 , 含演示地址
要求 必备知识 本文要求基本了解 Adobe Flex编程知识和JAVA基础知识. 开发环境 MyEclipse10/Flash Builder4.6/Flash Player11及以上 演示地址 演 ...
- flex4 s:Datagrid <s:typicalItem
<s:DataGird <s:typicalItem 这个标签相信大家很陌生吧, 我也是今天准备讲的时候才看到,估计是 flex4.5.1 新加东西,果然摸索 了下,这个标签作用也蛮好用的 ...
- ArcGIS API For Javascript_4.8-渲染器SimpleRenderer
SimpleRenderer require(["esri/renderers/SimpleRenderer"], function(SimpleRenderer) { /* co ...
- ArcGIS API For Javascript_4.8-渲染器Renderer
渲染器:Renderer 类:esri / renderers / Renderer 继承: Renderer->Accessor 子类: ClassBreaksRenderer , Heatm ...
- Flex4 DataGrid实现可复制单元格,同时解决自定义GridItemRenderer出现1009错误的方法
原创内容,如需转载,请注明出处,谢谢 最近在项目中发现Flex的DataGrid不支持内容复制,在涉及到保护敏感数据时倒是很有用处,但大部分情况下,我们还是希望客户能够直接复制DataGrid单元格中 ...
- Flex4+BlazeDS+JAVA+MySql 构建J2EE工程 对用户信息进行管理实例
要求 必备知识 本文要求基本了解 Adobe Flex编程知识和JAVA基础知识. 开发环境 MyEclipse10/Flash Builder4.6/Flash Player11及以上 演示地址 演 ...
- 07 Django REST Framework 解析器与渲染器
01-解析器 REST 框架包括一些内置的Parser类,允许你接受各种媒体类型的请求.还支持定义自己的自定义解析器,这使你可以灵活地设计API接受的媒体类型. 注意: 开发客户端应用程序时应该始终记 ...
- jeecg自定义datagrid查询
为什么要写这篇文章? 我们了解,使用 jeecg 提供的 CriteriaQuery 查询方式,确实能满足绝大数的需求,但是往往有那么个比较复杂的情况,需要我们直接去写 sql,比如多表查询呀等等等等 ...
- JEECG中datagrid方法自定义查询条件
自定义加添加查询条件的用法: CriteriaQuery cq = new CriteriaQuery(EquipmentEntity.class, dataGrid); //查询条件组装器 org. ...
随机推荐
- springMVC+Java验证码完善注册功能
这篇文章简单的写了一个java验证码,为之前写过的springMVC注册功能加上验证码,验证码的作用就不多说了,防止机器人程序恶意注册什么的.. 其中User.java,加上了password和cod ...
- 苹果4S
港版.4S.白.非翻新机.16G.联通3G移动2G电信2G 1000 美版.4S.白.翻新.16G.联通3G移动2G电信3G 980
- apache 配置
apache 2.4.9 httpd-vhosts.conf部分 <VirtualHost *:81> //配置端口 DocumentRoot "E:/H ...
- 7.hibernat实现双向一对多(多对一)
1.创建如下项目结构 2.在项目的src下创建hibernate.cfg.xml主配置文件 <?xml version="1.0" encoding="UTF-8& ...
- Lightoj 1066 Gathering Food (bfs)
Description Winter is approaching! The weather is getting colder and days are becoming shorter. The ...
- 小米2s刷机
每次系统内存不足,卡的不行就恨不得马上换新手机,发现手机也没有什么大的毛病,也没有其他苛刻的要求. 换个新系统继续使用吧,除了屏幕小了一点,将就了吧.物尽其责,坚决抵制过度消费. 小米手机2s 16G ...
- Github 修正上传时“this exceeds GitHub’s file size limit of 100 MB”错误
自己的项目的版本控制用的是Git,代码仓库在github托管.项目里用到了IJKMediaFramework 想把代码push到github上,结果出错了,被拒绝,具体信息是: Total 324 ( ...
- java的静态方法的使用
静态的方法和属性,你可以这么理解,就是所有对象公用的,比如一个属性是这样定义的: private static String name; 那么他的意思就是说,因为他是静态的,我所有的对象的name属性 ...
- Ubuntu11.10 E: Unable to locate package ubuntu-restricted-extras
最近在ubuntu11.10下安装支持多媒体播放的插件时遇到一些问题,在此小记一下. 首先是ubuntu11.10的安装,基本上是一键安装,在此不细说. 1.此版本和以前使用的ubuntu版本风格不太 ...
- CDOJ 1324 卿学姐与公主 分块
题目地址 分块模板 #include<cstdio> #include<algorithm> #include<math.h> using namespace st ...