<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/01/27/using-a-checkbox-control-as-a-list-item-renderer-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:vo="*"
    layout="horizontal"
    verticalAlign="middle"
    backgroundColor="white"
    creationComplete="init();">
 
 <mx:Script>
  <![CDATA[
   import mx.events.CollectionEvent;
   import mx.utils.ObjectUtil;
   
   private function init():void {
    arrColl.dispatchEvent(new CollectionEvent(CollectionEvent.COLLECTION_CHANGE));
   }
   
   private function arrColl_collectionChange(evt:CollectionEvent):void {
    try {
     var tArr:Array = arrColl.source.filter(selectedOnly);
     textArea.text = ObjectUtil.toString(tArr);
     lbl.text = tArr.length.toString() + " item(s) selected";
    } catch (err:Error) {
     // ignore.
    }
   }
   
   private function selectedOnly(item:ListItemValueObject, idx:uint, arr:Array):Boolean {
    return item.isSelected;
   }
  ]]>
 </mx:Script>
 
 <mx:Array id="arr">
  <vo:ListItemValueObject label="One" isSelected="true" />
  <vo:ListItemValueObject label="Two" isSelected="true" />
  <vo:ListItemValueObject label="Three" isSelected="true" />
  <vo:ListItemValueObject label="Four" isSelected="true" />
  <vo:ListItemValueObject label="Five" isSelected="false" />
  <vo:ListItemValueObject label="Six" isSelected="false" />
  <vo:ListItemValueObject label="Seven" isSelected="false" />
  <vo:ListItemValueObject label="Eight" isSelected="false" />
  <vo:ListItemValueObject label="Nine" isSelected="false" />
  <vo:ListItemValueObject label="Ten" isSelected="false" />
  <vo:ListItemValueObject label="Eleven" isSelected="false" />
  <vo:ListItemValueObject label="Twelve" isSelected="false" />
 </mx:Array>
 
 <mx:ArrayCollection id="arrColl"
      source="{arr}"
      collectionChange="arrColl_collectionChange(event);" />
 
 <mx:Panel id="panel"
     title="Items"
     status="{arrColl.length} total"
     styleName="opaquePanel">
  <mx:List id="list"
     dataProvider="{arrColl}"
     alternatingItemColors="[#EEEEEE, white]"
     width="150"
     rowCount="8">
   <mx:itemRenderer>
    <mx:Component>
     <mx:CheckBox selectedField="isSelected"
         change="onChange(event);">
      <mx:Script>
       <![CDATA[
        private function onChange(evt:Event):void {
         data.isSelected = !data.isSelected;
        }
       ]]>
      </mx:Script>
     </mx:CheckBox>
    </mx:Component>
   </mx:itemRenderer>
  </mx:List>
  <mx:ControlBar horizontalAlign="right">
   <mx:Label id="lbl" />
  </mx:ControlBar>
 </mx:Panel>
 
 <mx:TextArea id="textArea"
     verticalScrollPolicy="on"
     width="100%"
     height="{panel.height}" />
 
</mx:Application>

package
{
 public class ListItemValueObject
 {  
  [Bindable]
  public var label:String;
  
  [Bindable]
  public var isSelected:Boolean;
  
  public function ListItemValueObject() {
   super();
  }
 }
}

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/12/using-a-combobox-to-filter-items-in-a-datagrid-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="vertical"
    verticalAlign="middle"
    backgroundColor="white">
 
 <mx:Script>
  <![CDATA[
   import mx.controls.dataGridClasses.DataGridColumn;
   
   private function toggleFilter():void {
    if (checkBox.selected) {
     arrColl.filterFunction = processFilter;
    } else {
     arrColl.filterFunction = null;
    }
    arrColl.refresh();
   }
   
   private function processFilter(item:Object):Boolean {
    return parseFloat(item.value) == 0;
   }
   
   private function value_labelFunc(item:Object, col:DataGridColumn):String {
    return item[col.dataField].toFixed(2);
   }
  ]]>
 </mx:Script>
 
 <mx:ArrayCollection id="arrColl">
  <mx:source>
   <mx:Array>
    <mx:Object name="ColdFusion" value="0.00" />
    <mx:Object name="Dreamweaver" value="0.12" />
    <mx:Object name="Fireworks" value="1.01" />
    <mx:Object name="Flash" value="0" />
    <mx:Object name="Flash Player" value="-0.00" />
    <mx:Object name="Flex" value="0.00" />
    <mx:Object name="Illustrator" value="2.92" />
    <mx:Object name="Lightroom" value="0.32" />
    <mx:Object name="Photoshop" value="0.06" />
   </mx:Array>
  </mx:source>
 </mx:ArrayCollection>
 
 <mx:Panel status="{arrColl.length}/{arrColl.source.length} item(s)">
  <mx:DataGrid id="dataGrid"
      dataProvider="{arrColl}"
      verticalScrollPolicy="on">
   <mx:columns>
    <mx:DataGridColumn dataField="name" />
    <mx:DataGridColumn dataField="value"
           labelFunction="value_labelFunc" />
   </mx:columns>
  </mx:DataGrid>
  <mx:ControlBar>
   <mx:CheckBox id="checkBox"
       label="Filter DataGrid"
       click="toggleFilter();" />
  </mx:ControlBar>
 </mx:Panel>
 
</mx:Application>

flex Datagrid checkbox的更多相关文章

  1. flex datagrid checkbox选中项目

    <?xml version="1.0" encoding="utf-8"?>  <mx:Application xmlns:fx=" ...

  2. Flex DataGrid可编辑对象实现Enter跳转

    来源:http://blog.sina.com.cn/s/blog_5ed17a730100vrja.html 在Flex DataGrid中实现点击Enter键可编辑对象跳转<?xml ver ...

  3. Flex DataGrid 添加控件

    哈喽,又和大家见面了.今天要写的东西是关于Flex DataGrid添加“编辑”或“删除”按钮. 下面是部分代码: <mx:DataGrid id="dgShow" x=&q ...

  4. easyui datagrid checkbox multiple columns have been done do

    lengku1987   2013-01-06 22:27:47   Sponsored Links   easyui datagrid checkbox multiple columns have ...

  5. Flex带Checkbox的Tree

    想把Flex自带的Tree控件改成带有checkbox的样式. 原本以为同DataGrid一样,添加一个ItemRenderer就行,结果发现行不通. 进Tree控件的源码看了一下,发现Tree在自己 ...

  6. jQuery EasyUI DataGrid Checkbox 数据设定与取值

    纯粹做个记录,以免日后忘记该怎么设定. 这一篇将会说明两种使用 jQuery EasyUI DataGrid 的 Checkbox 设定方式,以及在既有数据下将 checked 为 true 的该笔数 ...

  7. EasyUI datagrid checkbox数据设定与取值(转自http://blog.csdn.net/baronyang/article/dnetails/9323463,感谢分享,谢谢)

    这一篇将会说明两种使用 jQuery EasyUI DataGrid 的 Checkbox 设定方式,以及在既有数据下将 checked 为 true 的该笔数据列的 Checkbox 设定为 Che ...

  8. wpf DataGrid CheckBox列全选

    最近在wpf项目中遇到当DataGrid的header中的checkbox选中,让该列的checkbox全选问题,为了不让程序员写自己的一堆事件,现写了一个自己的自定义控件 在DataGrid的 &l ...

  9. EasyUI DataGrid Checkbox 多选 获取选中行中的内容

    <table id='grid' class='easyui-datagrid' style='width:950px;height:405px' url='Ajax-index.php?mod ...

随机推荐

  1. css 笔记1

    type="text/css"的作用是什么?它是CSS样式的标记.type->类型,这里是style的属性text/css ->文本/css,即css文本type=&q ...

  2. January 11 2017 Week 2nd Wednesday

    One always has time enough, if one will apply it well. 如果你能好好地利用,你总有足够的时间. If you always feel that y ...

  3. kafka部分重要参数配置-broker端参数

    broker端参数主要在config/server.properties目录下设置: 启动命令:nohup ./kafka-server-start.sh -daemon ../config/serv ...

  4. Java日期格式化参数对照表

    Symbol Meaning Presentation Example G era designator Text AD y year Number 2009 M month in year Text ...

  5. Discuz的一处越权操作,强制回复无权限帖子

    合购vip  等教程论坛  都用的是Discuz 看操作步骤: 随便找一处vip教程 接下来 我们审查元素 找到这段代码 然后修改 <a href="http://xxx.xxx.xx ...

  6. java构造方法-this关键字的用法

    public class constructor { public static void main(String[] args) { // TODO Auto-generated method st ...

  7. 0-创建scott数据

    CREATE TABLE dept (  deptno INT PRIMARY KEY,  dname VARCHAR(14),  loc VARCHAR(13) );   INSERT INTO d ...

  8. Kali-linux渗透攻击应用

    前面依次介绍了Armitage.MSFCONSOLE和MSFCLI接口的概念及使用.本节将介绍使用MSFCONSOLE工具渗透攻击MySQL数据库服务.PostgreSQL数据库服务.Tomcat服务 ...

  9. java的四舍五入

    四舍五入是我们小学的数学问题,这个问题对于我们程序猿来说就类似于1到10的加减乘除那么简单了.在讲解之间我们先看如下一个经典的案例: public static void main(String[] ...

  10. ServletContextListener在Springboot中的使用

    ServletContextListener是servlet容器中的一个API接口, 它用来监听ServletContext的生命周期,也就是相当于用来监听Web应用的生命周期.今天我们就来说说如何在 ...