首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

Flex DataGrid CheckBox selectAll 全选兑现

2012-11-04 
Flex DataGrid CheckBox selectAll 全选实现http://hi.baidu.com/qiyangyang2009/blog/item/e52825dc14be1

Flex DataGrid CheckBox selectAll 全选实现
http://hi.baidu.com/qiyangyang2009/blog/item/e52825dc14be10fd76c63885.html/cmtid/fc9f115984c8278e800a18c1


package com.sintrue.components.datagridcheckbox{ import mx.controls.dataGridClasses.DataGridColumn; public class CheckBoxHeaderColumn extends DataGridColumn { public function CheckBoxHeaderColumn(columnName:String=null) { super(columnName); } /**is the checkbox in header selected**/ public var selected:Boolean = false; }}
二,创建HeaderRenderer类,继承自CheckBox

package com.sintrue.components.datagridcheckbox{ import flash.events.Event; import flash.events.MouseEvent; import mx.controls.CheckBox; import mx.controls.DataGrid; import mx.events.DataGridEvent; public class CheckBoxHeaderRenderer extends CheckBox {  public function CheckBoxHeaderRenderer()  {   super();   //addEventListener("click", clickHandler);  }  private var _data:CheckBoxHeaderColumn;  override public function get data():Object  {   return _data;  }  override public function set data(value:Object):void  {   _data = value as CheckBoxHeaderColumn;   DataGrid(listData.owner).addEventListener(DataGridEvent.HEADER_RELEASE, sortEventHandler);   selected = _data.selected;  }  private function sortEventHandler(event:DataGridEvent):void  {   if (event.itemRenderer == this)    event.preventDefault();  }  override protected function clickHandler(event:MouseEvent):void  {   super.clickHandler(event);   data.selected = selected;   var dg:DataGrid = DataGrid(listData.owner);//get DataGrid object   if(dg.dataProvider.length>0){            for(var i:int = 0; i < dg.dataProvider.length ; i++){             dg.dataProvider[i].@selected = this.selected;         }           }           dg.dataProvider.refresh();  } }} 

三 创建DataRenderer,继承自CheckBox

package com.sintrue.components.datagridcheckbox{ import flash.events.Event; import mx.controls.CheckBox; public class CheckBoxItemDataRenderer extends CheckBox {  public function CheckBoxItemDataRenderer()  {   super();   this.addEventListener(Event.CHANGE, changeHandler);  }  override public function set data(value:Object):void  {   super.data = value;   this.selected = listData.label == 'true';  }  protected function changeHandler(event : Event) : void  {   if(data is XML)   data.@selected = this.selected;   else   data.selected = this.selected;  } }}

四,使用

<dataGrid:CheckBoxHeaderColumn textAlign="center"            dataField="@selected" width="26"            itemRenderer="com.sintrue.components.datagridcheckbox.CheckBoxItemDataRenderer"            headerRenderer="com.sintrue.components.datagridcheckbox"/>





http://cookbooks.adobe.com/post_Select_all_checkboxes_in_a_datagrid-10786.html
http://www.justskins.com/forums/select-all-checkboxes-in-85899.html

http://www.fengfly.com/plus/view-172194-1.html



这个最简单好用.....哈哈
spark的checkbox没有data这个属性...mx的checkbox有data这个属性....

Select all checkboxes in datagrid via code Im doing this:private function selectAll():void {var length : int = myDataGrid.dataProvider.length;for( var i : int = 0; i < length; i++ ){var item : Object = myAccounts.getItemAt( i );item["Include"] = '1';}myAccounts.refresh();}Include is my column of checkboxs in my datagrid<mx:DataGridColumn headerText="Include" dataField="Include" width="58"sortable="false"><mx:itemRenderer><mx:Component><mx:HBox horizontalAlign="center"><mx:CheckBox click="data.Include=!data.Include"selected="{data.Include}" themeColor="#73B9B9"/></mx:HBox></mx:Component></mx:itemRenderer></mx:DataGridColumn>


热点排行