Datagrid popup as itemEditor(翻译转载)弹出式的数据表编辑器的实现

导读:
  This isn’t as difficult as some may think. Basically your itemRenderer opens up a popup. When the renderer creates the popup, it sets an “opener” property on the popup pointing back to “this”, which is the itemRenderer. That way, when the editing is finished in the popup, the popup can pass data back to a function in the itemRenderer to do the update, close itself, and set focus back to the itemRenderer.也许大家会认为这东西不难,只要简单的将ITEMRENDER作成一个POPUP不久行了,当RENDER创建一个POPUP,他设置一个OPENER属性在POPUP上回指向THIS也就是ITMERENDER,这样做就可以使编辑在POPUP里面完成,并且将数据传回GRID并设置焦点
  Here is the code for the app: 代码如下
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
editable="false"wordWrap="true"
headerText="Article Name"
itemRenderer="MyRenderer"dataField="articleName"/>  editable="false"wordWrap="true"
  headerText="Article Name"
  itemRenderer="MyRenderer"dataField="articleName"/>
  
  
  
  
  Here is the itemRenderer:
  
  
implements="mx.controls.listClasses.IDropInListItemRenderer"
toolTip="Double Click to Edit…"doubleClick="callLater(openPopup)"doubleClickEnabled="true"
text="{txt}">  implements="mx.controls.listClasses.IDropInListItemRenderer"
  toolTip="Double Click to Edit…"doubleClick="callLater(openPopup)"doubleClickEnabled="true"
  text="{txt}">
  
  
importmx.controls.DataGrid
importmx.controls.listClasses.ListData
importmx.controls.dataGridClasses.DataGridListData
importmx.controls.listClasses.BaseListData
importmx.managers.PopUpManager
importmx.events.FlexEvent
private<  importmx.controls.DataGrid
  importmx.controls.listClasses.ListData
  importmx.controls.dataGridClasses.DataGridListData
  importmx.controls.listClasses.BaseListData
  importmx.managers.PopUpManager
  importmx.events.FlexEvent
  privatevar_listData:DataGridListData;
  
  [Bindable]
  publicvartxt:String
  
  privatevarpop:Popup
  override publicfunctionsetdata(value:Object):void{
  super.data= value;
  txt=data[_listData.dataField]
  }
  override publicfunctiongetdata():Object{
  returnsuper.data
  }
  
  override publicfunctiongetlistData():BaseListData
  {
  return_listData;
  }
  
  override publicfunctionsetlistData(value:BaseListData):void
  {
  _listData = DataGridListData(value)
  }
  privatefunctionopenPopup():void{
  pop= Popup(PopUpManager.createPopUp(this.owner,Popup,true))
  pop.txt=this.txt
  pop.opener=this
  }
  
  publicfunctionupdateDP(str:String):void{
  varmyDG:DataGrid=this.owneras DataGrid;
  varrow:int=_listData.rowIndex+myDG.verticalScrollPosition
  this.data[_listData.dataField]=str;
  myDG.dataProvider.itemUpdated(data)
  }
  ]]>
  
  
  
  Here is the popup:
  
  
width="350"height="250"showCloseButton="false"creationComplete="centerMe()"
defaultButton="{btnSave}">  width="350"height="250"showCloseButton="false"creationComplete="centerMe()"
  defaultButton="{btnSave}">
  
  
importmx.managers.FocusManager
importmx.managers.PopUpManager
[Bindable]
public<  importmx.managers.FocusManager
  importmx.managers.PopUpManager
  [Bindable]
  publicvartxt:String
  
  publicvaropener:Object
  
  
  privatefunctionsave():void{
  (opener as MyRenderer).updateDP(ta.text)
  cancel()
  }
  
  privatefunctioncancel():void{
  PopUpManager.removePopUp(this)
  returnFocus()
  }
  
  privatefunctionreturnFocus():void{
  opener.setFocus()
  }
  
  privatefunctioncenterMe():void{
  PopUpManager.centerPopUp(this)
  ta.setFocus()
  }
  
  ]]>
  
  
  
  
  
  
  
  
  
个人最喜欢这样的文章,这是STLOUIS带来的一篇文章,他的风格我非常喜欢。用代码说话,但是又指出实现的关键之处
本文转自
http://blog.739saintlouis.com/2007/12/12/datagrid-popup-as-itemeditor/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值