Flex DataGrid插入 删除一行

<?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" minWidth="955" minHeight="600">
 <fx:Declarations>
  <!-- 将非可视元素(例如服务、值对象)放在此处 -->
 </fx:Declarations>
 <fx:Script>
  <![CDATA[
   import flash.profiler.showRedrawRegions;
   import flexunit.utils.ArrayList;
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.controls.List;
   import mx.events.DragEvent;
   import mx.events.FlexEvent;
   [Bindable]
   public var lix:ArrayCollection =new  ArrayCollection([{name:"1",phone:"456",email:"789"},{name:"2",phone:"2",email:"3"}]);
   protected function berfor():void {
    trace(dg.dataProvider.length);
    var item:Object = new Object(); 
    var ay:ArrayCollection=dg.dataProvider as ArrayCollection; 
    ay.addItemAt(item,dg.selectedIndex);
    for(var i:int;i<ay.length;i++){
     ay.getItemAt(i).name=i+1;
    }
   }
   
   protected function affter():void{
    var item:Object = new Object(); 
    var ay:ArrayCollection=dg.dataProvider as ArrayCollection; 
    ay.addItemAt(item,dg.selectedIndex+1);
    for(var i:int;i<ay.length;i++){
     ay.getItemAt(i).name=i+1;
    }
   }
   protected function dele():void{
    var ay:ArrayCollection=dg.dataProvider as ArrayCollection;
    var index:int =dg.selectedIndex;
     dg.dataProvider.removeItemAt(index);
     index=dg.selectedIndex-1;
     dg.dataProvider.refresh();
     for(var i:int;i<ay.length;i++){
      ay.getItemAt(i).name=i+1;
     }
    }
   
  ]]>
 </fx:Script>
 <s:Panel x="0" y="10" width="100%" height="100%">
  <s:Button x="128" y="12" label="在之前插入" enabled="{dg.selectedIndex ==-1?false:true}" click="berfor()"/>
  <s:Button x="287" y="12" label="在之后插入" enabled="{dg.selectedIndex ==-1?false:true}" click="affter()"/>
  <s:Button x="445" y="12" label="删除" enabled="{dg.selectedIndex ==-1?false:true}" click="dele()"/>
   <mx:DataGrid id="dg" x="34" y="41" width="581" height="321" dataProvider="{ lix }"
       rowCount="5" editable="true">
    <mx:columns>
     <mx:DataGridColumn dataField="name" headerText="序号" />
     <mx:DataGridColumn dataField="phone" headerText="X坐标"/>
     <mx:DataGridColumn dataField="email" headerText="Y坐标"/>
    </mx:columns>
   </mx:DataGrid>
 </s:Panel>
 
 
 
</s:Application>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值