flex AdvancedDataGrid的使用

flex端

 

一、引进 xmlns:group="comp.group.*"

二、变量 

			[Bindable]
			private var groupArray:ArrayCollection ;

三、方法:
      //排序方法
     	private function compare(a:Object, b:Object, fields:Array = null):int
			{
				if (a == null && b == null)
					return 0;
				if (a == null)
					return 1;
				if (b == null)
					return -1;
				if (a.projectParentTypeName == b.projectParentTypeName)
				{
					if (a.projectTypeCd < b.projectTypeCd)
						return -1;
					if (a.projectTypeCd > b.projectTypeCd)
						return 1;
					return 0;
				}
				return (a.projectParentTypeName < b.projectParentTypeName ? -1 : 1);
			}
			
			//加载数据方法
			HttpUtil.doPost("bfPlanInvestigateAction!getBfPlanInvestigateByPlanId.do",param,function(obj:Object):void{
						groupArray = new ArrayCollection(obj.data);
						gc.refresh();
					});
					
四、定义grid
     	<mx:AdvancedDataGrid id="grid" width="100%" height="100%" headerColors="[#DCE7F1,#E7EFF5]" alternatingItemColors="[#FFFFFF,#FAFAFA]"  headerHeight="30" 
										 sortableColumns="false" horizontalGridLines="false" horizontalGridLineColor="0xffffff"
										 designViewDataType="flat" horizontalScrollPolicy="auto"
										 editable="true" initialize="gc.refresh();"    sortExpertMode="true"
										 displayItemsExpanded="true"  >
						<mx:dataProvider>
							<mx:GroupingCollection2 id="gc" source="{groupArray}"  >
								<mx:Grouping compareFunction="compare"> 
									<mx:GroupingField name="projectParentTypeName" caseInsensitive="true" />
								</mx:Grouping>
							</mx:GroupingCollection2>
						</mx:dataProvider>
						<mx:groupedColumns>
							<mx:AdvancedDataGridColumn dataField="projectTypeName" headerText="项目类型"  width="200"  editable="false"/>
							<mx:AdvancedDataGridColumn dataField="unitName" headerText="单位"  width="80"  editable="false"/>
							<mx:AdvancedDataGridColumn dataField="projectQty" headerText="项目工程量"  width="100" editable="true"  
													   >
								<mx:itemEditor>
									<fx:Component>
										<mx:TextInput restrict="0-9"    minWidth="0"  >
											<!--如果是根节点的话,不能编辑-->
											<fx:Script>
												<![CDATA[
													import pipi.Util;
													public function get value() : String
													{
														return value;
													}
													override public function set data(value:Object):void
													{
													  //如果是根节点,不让编辑
														if(value.children ==null){
															this.enabled = true;
														}else{
															this.enabled = false;
														}
														super.data = value;
													}
												]]>
											</fx:Script>
										</mx:TextInput>
									</fx:Component>
								</mx:itemEditor>
							</mx:AdvancedDataGridColumn>
							<mx:AdvancedDataGridColumn dataField="planInvId" headerText="planInvId" visible="false"  />
							<mx:AdvancedDataGridColumn dataField="projectParentTypeName" headerText="父节点" visible="false"  editable="false"/>
						</mx:groupedColumns>
					</mx:AdvancedDataGrid>


 

java端:

      数据要有父节点,子节点就可以了!

 

但这个group会有个问题,就是第一级如果没有第二级的话,就会照成它自己本身会成为第二级,看起来就有点怪!所以改成用treeGrid..

你可能感兴趣的:(String,function,object,Flex,null,import)