flex dataGrid 删除 修改 弹出框
form 主页面
<?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" initialize="setup()"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import flashx.textLayout.edit.SelectionManager;
import mx.collections.HierarchicalData;
import mx.events.*;
import mx.managers.PopUpManager;
import mx.rpc.events.ResultEvent;
import org.flexunit.runner.Result;
[Bindable]
private var buttonRender1:ClassFactory;
private function setup():void{
buttonRender1 = new ClassFactory(ButtonItmRender);
buttonRender1.properties = {stateHost:this
,displayName:"修改",type:'edit'};
}
protected function button1_clickHandler(event:MouseEvent):void
{
var form2:AlertPage=new AlertPage();
PopUpManager.addPopUp(form2,this, true);
PopUpManager.centerPopUp(form2);
}
protected function endTimes_changeHandler(event:Event):void
{
// TODO Auto-generated method stub
}
protected function starTimes_changeHandler(event:CalendarLayoutChangeEvent):void
{
// TODO Auto-generated method stub
}
protected function datefield1_changeHandler(event:CalendarLayoutChangeEvent):void
{
// TODO Auto-generated method stub
}
public function delected():void{
var item:Object=gri.selectedItem;
var i:int=(gri.dataProvider as ArrayCollection).getItemIndex(item);
(gri.dataProvider as ArrayCollection).removeItemAt(i);
}
//public function update():void{
//var form2:AlertPage=new AlertPage();
//PopUpManager.addPopUp(form2,this, true);
//PopUpManager.centerPopUp(form2);
//
//}
public var listData:ArrayCollection = new ArrayCollection();
protected function button2_clickHandler(event:MouseEvent):void
{
var arr1:ArrayCollection=new ArrayCollection();
for(var i:int=0;i<listData.length;i++){
var obj:Object = listData.getItemAt(i);
if(code.text !=null && code.text.length > 0){
if((obj.code as String).indexOf(code.text) < 0)
continue;
};
if(name1.text !=null && name1.text.length > 0){
if((obj.name as String).indexOf(name1.text) < 0)
continue;
};
if(starTimes.text !=null && starTimes.text.length >0){
if((obj.starTimes as String).indexOf(starTimes.text) < 0)
continue;
};
}
arr1.addItem(obj);
gri.dataProvider = arr1;
}
protected function application1_initializeHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<mx:Form>
<mx:FormHeading label="设备维护"/>
<mx:HBox>
<mx:FormItem label="编码">
<mx:TextInput width="59" id="code"/>
</mx:FormItem>
<mx:FormItem label="名称">
<mx:TextInput width="59" id="name1"/>
</mx:FormItem>
<mx:FormItem label="创建时间">
<mx:DateField id="starTimes" change="datefield1_changeHandler(event)" width="79"/>
</mx:FormItem>
<s:Label text="到" x="432" y="65"/>
<mx:FormItem width="73" height="22">
<mx:DateField id="endTimes" change="endTimes_changeHandler(event)" x="211" y="10" width="85" height="33"/>
</mx:FormItem>
<s:Label text="状态" x="565" y="65"/>
<mx:ComboBox width="61" x="597" y="64">
<mx:dataProvider>
<s:ArrayCollection>
<fx:Object label="有效"/>
<fx:Object label="无效"/>
</s:ArrayCollection>
</mx:dataProvider>
</mx:ComboBox>
<mx:VBox>
<mx:Button label="新建" click="button1_clickHandler(event)" width="80" x="662" y="92"/>
<mx:Button label="查询" click="button2_clickHandler(event)" x="662" y="63" width="78"/>
</mx:VBox>
</mx:HBox>
<mx:DataGrid id="gri" x="83" y="133" width="655" height="219">
<mx:columns>
<mx:DataGridColumn headerText="编码" dataField="code" editorDataField="value"/>
<mx:DataGridColumn headerText="名称" dataField="name"/>
<mx:DataGridColumn headerText="创建时间" dataField="startTime"/>
<mx:DataGridColumn headerText="状态" dataField="state"/>
<mx:DataGridColumn headerText="操作" dataField="oprate" width="{width*0.12}" itemRenderer="{buttonRender1}"/>
<mx:DataGridColumn>
<mx:itemRenderer>
<fx:Component>
<mx:Button label="删除" click="outerDocument.delected()"/>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:Form>
</s:Application>
弹出页面
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="626" height="300">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.controls.Text;
import mx.managers.PopUpManager;
import mx.states.State;
import org.flexunit.internals.namespaces.classInternal;
import org.osmf.layout.AbsoluteLayoutFacet;
public function creationComplete(){
var arr:Object = (this.parentApplication as form).gri.selectedItem as Object;
code.text=arr.code;
name2.text=arr.name;
starTimes.text=arr.startTime;
state.text=arr.state;
}
protected function button1_clickHandler(event:MouseEvent):void
{
PopUpManager.removePopUp(this);
}
protected function button2_clickHandler(event:MouseEvent):void
{
var result:ArrayCollection= (this.parentApplication as form).gri.dataProvider as ArrayCollection;
if(null == result){
result = new ArrayCollection();
};
var obj:Object=new Object();
obj.code=code.text;
obj.name=name2.text;
obj.startTime=starTimes.text;
obj.state=state.text;
result.addItem(obj);
(this.parentApplication as form).listData.addItem(obj);
(this.parentApplication as form).gri.dataProvider = result;
PopUpManager.removePopUp(this);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:Label text="新建设备"/>
<mx:Form>
<mx:FormItem label="编码">
<mx:TextInput id="code"/>
</mx:FormItem>
<mx:FormItem label="名称">
<mx:TextInput id="name2"/>
</mx:FormItem>
<mx:FormItem label="创建时间">
<mx:DateField id="starTimes"/>
</mx:FormItem>
<mx:FormItem label="状态">
<mx:ComboBox id="state">
<mx:dataProvider>
<s:ArrayCollection id="oprate">
<fx:Object label="有效"/>
<fx:Object label="无效"/>
</s:ArrayCollection>
</mx:dataProvider>
</mx:ComboBox>
</mx:FormItem>
</mx:Form>
<s:HGroup>
<mx:Button label="保存" click="button2_clickHandler(event)"/>
<mx:Button label="取消" click="button1_clickHandler(event)"/>
</s:HGroup>
</mx:TitleWindow>
脚本
package
{
import flash.display.DisplayObject;
import flash.events.MouseEvent;
import mx.controls.Alert;
import mx.controls.Button;
import mx.controls.Text;
import mx.managers.PopUpManager;
import org.flexunit.asserts.fail;
public class ButtonItmRender extends Button
{
public var stateHost:Object;
public var displayName:String;
public var type:String;
public var sytleName:String;
public function ButtonItmRender()
{
super();
}
override public function set data(value:Object):void
{
super.data=value;
super.label=displayName;
super.styleName = sytleName;
}
override protected function clickHandler(event:MouseEvent):void
{
super.clickHandler(event);
//if(stateHost.hasOwnProperty('lnkBtnHandler')){
//(stateHost['lnkBtnHandler'] as Function).call(stateHost['lnkBtnHandler'],data,type);
var form2:AlertPage=new AlertPage();
PopUpManager.addPopUp(form2,stateHost as DisplayObject,fail);
PopUpManager.centerPopUp(form2);
}
}
}