<?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">
<s:layout>
<s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.collections.Sort;
import mx.collections.SortField;
[Bindable]
private var dgdp:ArrayCollection=new ArrayCollection();
protected function adddgitem():void
{
var o:Object=new Object();
o.id=in1.text;
o.name=in2.text;
o.score=in3.text;
o.classes=in4.text;
o.value=in5.text;
dgdp.addItem(o);
in1.text="";
in2.text="";
in3.text="";
in4.text="";
in5.text="";
var sort:Sort=new Sort();
var sortF:SortField=new SortField("score");//默认按score排序
sort.fields=new Array(sortF);
dgdp.sort=sort;
dgdp.refresh();
}
protected function deldgitem(i:int):void
{
if(dg.selectedIndex!=-1){
dgdp.removeItemAt(i);
}else{
return ;
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:DataGrid id="dg" width="400" height="300" requestedRowCount="5" dataProvider="{dgdp}">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="id" headerText="id"></s:GridColumn>
<s:GridColumn dataField="name" headerText="name"></s:GridColumn>
<s:GridColumn dataField="score" headerText="score"></s:GridColumn>
<s:GridColumn dataField="classes" headerText="classes"></s:GridColumn>
<s:GridColumn dataField="value" headerText="value"></s:GridColumn>
</s:ArrayList>
</s:columns>
</s:DataGrid>
<s:HGroup width="400" height="40" verticalAlign="middle" paddingLeft="5">
<s:TextInput id="in1" width="40"/>
<s:TextInput id="in2" width="40"/>
<s:TextInput id="in3" width="40"/>
<s:TextInput id="in4" width="40"/>
<s:TextInput id="in5" width="40"/>
<s:Button label="增加" click="adddgitem()"
enabled="{((in1.text=='')||(in2.text=='')||(in3.text=='')||(in4.text=='')||(in5.text==''))?false:true}"/>
<s:Button label="删除" click="deldgitem(dg.selectedIndex)" enabled="{(dg.selectedIndex!=-1)?true:false}"/>
</s:HGroup>
</s:Application>