导读:
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/
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/