flex 动态构建 datagrid

1 DataGrid 与 AdvancedDataGrid
先提下这个的原因就是这项目时有一个问题让我走了不少弯路。DataGrid的dataField支持访问类成员变量的属性 而AdvancedDataGrid不支持。
package myAs
{
	[Bindable]
	[RemoteClass(alias = "ms.model.PorderDetail")]
	public class PorderDetailF
	{
		
		public var  pordid : int;
		public var  porder : Object; // 主表ID
		public var  item : Object; // 商品ID
		public var  quantity :int ; // 数量
		public var  price :Number ; // 总价格
		public var   store :Object ; // 进入仓库ID
		public var  code : String;
		public function PorderDetailF()
		{
		}
	}
}
可以用<mx:DataGridColumn  width="100" headerText="仓库名称" dataField="store.name" />访问  而AdvancedDataGrid就不行

2 动态构建DataGrid

<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
		<mx:ChannelSet id="cs">
			<mx:AMFChannel uri="/mobile-store-system/messagebroker/amf"/>
		</mx:ChannelSet>
		<mx:RemoteObject id="StoreInOutManager"   
						 destination="storeInOutManager" channelSet="{cs}">
		<mx:method name="getStoreInOutByDate" result="handleResult_getStoreInOutByDate(event)"/>
		</mx:RemoteObject> 
		
		<mx:RemoteObject id="InOutDetail"   
						 destination="inOutDetailManager" channelSet="{cs}">
			<mx:method name="GetlistDetailbyItem" result="handleResult_GetlistDetailbyItem(event)"/> 
		
			
		</mx:RemoteObject> 
		
	</fx:Declarations>
<fx:Script>
import mx.controls.DataGrid;
import mx.controls.dataGridClasses.DataGridColumn;
public function init()
			{
				this.title=dataType+"   "+"于  "+startTime+" 至 "+endTime;
				
				if(dataType=="药品销售详细报表")
				{
				
					
					var column1:DataGridColumn = new DataGridColumn();
					column1.headerText = "单据号";
					column1.dataField = "code";
					//column1.width=100;
					var column2:DataGridColumn = new DataGridColumn();
					column2.headerText = "总金额";
					column2.dataField = "totalM";
					//column2.width=100;
					var column3:DataGridColumn = new DataGridColumn();
					column3.headerText = "操作员";
					column3.dataField = "operator";
					//column3.width=100;
					var column4:DataGridColumn = new DataGridColumn();
					column4.headerText = "日期";
					column4.dataField = "billDate";
					//column4.width=250;
					
					myDg.columns = myDg.columns.concat(column1);
					myDg.columns = myDg.columns.concat(column2);
					myDg.columns = myDg.columns.concat(column3);
					myDg.columns = myDg.columns.concat(column4);
	                
					StoreInOutManager.getStoreInOutByDate(startTime,endTime);
				}
				else if(dataType=="单一药品收入详细报表")
				{
					
					
					var column1:DataGridColumn = new DataGridColumn();
					column1.headerText = "数量";
					column1.dataField = "quantity";
					//column1.width=100;
					var column2:DataGridColumn = new DataGridColumn();
					column2.headerText = "总价";
					column2.dataField = "price";
					//column2.width=150;
					var column3:DataGridColumn = new DataGridColumn();
					column3.headerText = "日期";
					column3.dataField = "date";
				//	column3.width=250;
					
					myDg.columns = myDg.columns.concat(column1);
					myDg.columns = myDg.columns.concat(column2);
					myDg.columns = myDg.columns.concat(column3);
			
					
					
					InOutDetail.GetlistDetailbyItem(startTime,endTime,singleItemName);
				}
				
			}
public function handleResult_GetlistDetailbyItem(event:ResultEvent):void
			{
				var tempList :  Array ;
				if(event.result!=null){
					tempList= ArrayUtil.toArray(event.result);
					myDg.dataProvider=tempList[0];
				}
				else
				{
					Alert.show("数据提供异常,无法生成图表");
				}
			}
			public function handleResult_getStoreInOutByDate(event:ResultEvent):void
			{
				var tempList :  Array ;
				if(event.result!=null){
					tempList= ArrayUtil.toArray(event.result);
					myDg.dataProvider=tempList[0];
				}
				else
				{
					Alert.show("数据提供异常,无法生成图表");
				}
			}

</fx:Script>


<mx:DataGrid id="myDg" width="100%" height="100%">




关于 datagrid 各属性可以参考
http://blog.myspace.cn/e/403559246.htm

你可能感兴趣的:(datagrid,Flex)