专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Flex

flex DataGrid编者单元格并获取新的值

发布时间:2011-06-27 19:44:14 文章来源:www.iduyao.cn 采编人员:星星草
flex DataGrid编辑单元格并获取新的值

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal">
 <mx:Panel width="458" height="313" layout="absolute">
  <mx:Label id="lbl" x="19" y="10" text="" width="171" height="20"/>
  <mx:DataGrid id="dg" x="19" y="58" dataProvider="{arr}" editable="true" itemEditEnd="editHandle(event)"
    horizontalGridLines="true" horizontalGridLineColor="#B9F2C9" verticalGridLineColor="#B9F2C9">
   <mx:columns>
    <mx:DataGridColumn headerText="year" dataField="year" editable="false"/>
    <mx:DataGridColumn headerText="city" dataField="city" editable="false"/>
    <mx:DataGridColumn headerText="provice" dataField="provice" editable="false" sortable="false"/>
    <mx:DataGridColumn headerText="total" dataField="total"/>
   </mx:columns>
  </mx:DataGrid>
 </mx:Panel>
 <mx:Script>
  <![CDATA[
   import mx.controls.dataGridClasses.DataGridColumn;
   import mx.events.DataGridEvent;
   import mx.controls.Alert;
   import mx.collections.ArrayCollection;

   [Bindable]
   private var arr:ArrayCollection=new ArrayCollection([
   {year:2009,city:"Shanghai",provice:"上海",total:580000},
   {year:2009,city:"Beijing",provice:"河北省",total:7852020},
   {year:2009,city:"Nanjing",provice:"江苏省",total:895145},
   {year:2009,city:"Hangzhou",provice:"浙江省",total:4132415}]);

   private function editHandle(event:DataGridEvent):void{
    if(event.dataField=="total"){
     var cols:DataGridColumn=dg.columns[event.columnIndex];
     ///编辑前的值,没用到,只是想获得一下
     var s:String=event.itemRenderer.data.total;
     //编辑后新的值
     var newValue:String=dg.itemEditorInstance[cols.editorDataField];
     var tt:String;
     var num:Number=Number(tt);
     if(isNaN(num)){
      event.preventDefault();//恢复本来数据
      lbl.text="this is not num!";
     }else{
      lbl.text=tt;
      /*=======操作数据和数据库打交道=========*/
      /*省略*/
     }
    }
   }
   ]]>
  
</mx:Script>
</mx:Application>

1 楼 saboo 2011-06-28  
真晕:
itemEditEnd="editHandle(event)" 报错啊
原本我用的是AdvancedDataGrid 要用AdvancedDataGridEvent
private function editHandle(event:AdvancedDataGridEvent):void{
}

除了这样写,可以写成监听的形式么?
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: