troubleshooting Question

AdvancedDataGrid Tree Structure

Avatar of alamflex
alamflex asked on
Apache Flex
7 Comments1 Solution853 ViewsLast Modified:
AdvancedDataGrid Query:
1. As shown in the sample image i need to add multiple filter child nodes dynamically.
Here in this case ClusterBy,FilterComponent,AbstractQuestionSpecification,Operator.
2.For the added child nodes i need show delete button so that i can delete that added node dynamically

Refer the sample image.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" layout="vertical" creationComplete="init()">
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;
			import mx.controls.listClasses.IListItemRenderer; 
			private function init():void {
			private var student:ArrayCollection = new ArrayCollection(
				{Course:"Filter", children: [
						{Course:"ClusterBy", children:[
								{Course:"AttributeType", Boys:120, TotalStudent:180, PASSinper:98.0, FAILinper:2.0}
						{Course:"FilterComponent", children:[
								{Course:"ClusterAggregateFunction", Boys:120, TotalStudent:180, PASSinper:98.0, FAILinper:2.0}
						{Course:"AbstractQuestionSpecification", children:[
								{Course:"AttributeType", Boys:80, TotalStudent:180, PASSinper:98.0, FAILinper:2.0},
								{Course:"NodeColourRegex",Boys:80, TotalStudent:120, PASSinper:95, FAILinper:5},
								{Course:"NavigationStrategyComponentAlias", Boys: 80, TotalStudent:90, PASSinper:97.5, FAILinper:2.5},
								{Course:"Context", children:[
										{Course:"QuestionTypeHandler", children:[
												{Course:"AttributeType",Boys:80, TotalStudent:180, PASSinper:98.0, FAILinper:2.0},
												{Course:"Value",Boys:80, TotalStudent:180, PASSinper:98.0, FAILinper:2.0}
						{Course:"Operator", children:[
								{Course:"FilterComponentOperatorType", Boys: 80, TotalStudent:90, PASSinper:97.5, FAILinper:2.5} 
			private function save():void{"Saved...");
			private function add():void {
				var item:Object = {};
				if(student.length == 1){
					var course:Object = student.getItemAt(0);
					if(course != null){
						var o:Object;
						o = findCourse(course.children[0], "AttributeType");
						if(o != null)
							item.attributeType = o.Value;							
						o = findCourse(course.children[1], "ClusterAggregateFunction");
						if(o != null)
							item.clusterAggregateFunction = o.Value;

						o = findCourse(course.children[2], "AttributeType");
						if(o != null)
							item.abstractAttributeType = o.Value;

						o = findCourse(course.children[2], "NodeColourRegex");
						if(o != null)
							item.nodeColourRegex = o.Value;
						o = findCourse(course.children[2], "NavigationStrategyComponentAlias");
						if(o != null)
							item.navigationStrategyComponentAlias = o.Value;
						o = findCourse(course.children[2], "Value");
						if(o != null)
							item.value = o.Value;
			private function findCourse(parent:Object, name:String):Object{
				for(var i:uint = 0; i < parent.children.length; i++){
					var child:Object = parent.children[i];
					if(child.Course == name){
						return child;
					}else if(child.hasOwnProperty("children")){
						return findCourse(child, name);
				return null;
	<mx:Panel title="Include Filter" height="600" width="699">
		<mx:AdvancedDataGrid id="treeDg" sortExpertMode="true" displayItemsExpanded="true" height="363" x="13" y="13" width="669"
				<mx:HierarchicalData source="{student}" />
				<mx:AdvancedDataGridColumn dataField="Course" />
				<mx:AdvancedDataGridColumn dataField="Value"> 
							<mx:Canvas width="100%">
										override public function set data(value:Object):void{
	 = value;
											if(data != null)
												ti.text = data.Value;
										private function setValue(event:Event):void{
											if(data != null)
												data.Value =
								<mx:TextInput id="ti" visible="{data.hasOwnProperty('Boys')}" width="98%" change="setValue(event)"/>
		<mx:HBox width="100%" horizontalAlign="right" paddingRight="10" paddingBottom="10">
			<mx:Button label="Add" click="add()"/>
		<mx:DataGrid id="dg" horizontalCenter="0" verticalCenter="0" dataProvider="[]">
				<mx:DataGridColumn dataField="attributeType"/> 
				<mx:DataGridColumn dataField="clusterAggregateFunction" width="150" /> 
				<mx:DataGridColumn dataField="abstractAttributeType"/>
				<mx:DataGridColumn dataField="nodeColourRegex"/>
				<mx:DataGridColumn dataField="navigationStrategyComponentAlias"/> 
				<mx:DataGridColumn dataField="value"/>
			<mx:Spacer width="80%"/>
			<mx:Button paddingRight="20" label="Save" click="save()"/>

Open in new window

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros