Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 404
  • Last Modified:

AdvancedDataGrid

Hi,
AdvancedDataGrid Query

If you observe in the sample image when we expand clusterby by default it should contain Attributetype form without remove button for it. Next when we click on add button next to cluserby it should add mulitple nodes dynamically for example Attributetype and it should contain remove button for those added new nodes.And when we click on remove button it should remove that added nodes dynamically.

Simillarly for others also

1.ClusterBym

AttributeType

2.FilterComponent

ClusterAggregateFunction

3.AbstractQuestionSpecification

AttributeType
NodeColourRegex
NavigationStrategyComponentAlias

Below is my sample working code and image.

Thanks,
Alam.
<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

    <mx:Script>

        <![CDATA[

            import mx.collections.ArrayCollection;

            import mx.controls.Alert;

            import mx.controls.listClasses.IListItemRenderer;

            import mx.core.mx_internal;            

           

            [Bindable]

            private var student:ArrayCollection = new ArrayCollection(

                [

                    {Course:"Filter", children: [

                        {Course:"ClusterBy", showButtons:true, children:[

                            {Course:"AttributeType", Boys:120, TotalStudent:180, PASSinper:98.0, FAILinper:2.0}

                        ]

                        },

                        {Course:"FilterComponent",showButtons:true, children:[

                            {Course:"ClusterAggregateFunction", Boys:120, TotalStudent:180, PASSinper:98.0, FAILinper:2.0}

                        ]

                        },

                        {Course:"AbstractQuestionSpecification", showButtons:true, 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", showButtons:true, 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{

                Alert.show("Saved...");

            } 

                                                

            private function add():void {

                var item:Object = { };

                                                                var flag:Boolean = true;

                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) {                                                                                                                                                                                                      

                                                                                                                if(o.Value!=null && o.Value!="")

                                                                                                                                item.attributeType = o.Value;                                                                                                    

                                                                                                                else

                                                                                                                                flag=false;

                        }

                        o = findCourse(course.children[1], "ClusterAggregateFunction");

                        

                                                                                   if (o != null) {                                                                                                                   

                                                                                                                

                                                                                                                if(o.Value!=null && o.Value!="")

                                                                                                                                item.clusterAggregateFunction = o.Value;                                                                                           

                                                                                                                else

                                                                                                                                flag=false;

                        }

                        o = findCourse(course.children[2], "AttributeType");

                      

                                                                                                if (o != null) {                                                                                                                      

                                                                                                                

                                                                                                                if(o.Value!=null && o.Value!="")

                                                                                                                                item.attributeType2 = o.Value;                                                                                 

                                                                                                                else

                                                                                                                                flag=false;

                        }

                        o = findCourse(course.children[2], "NodeColourRegex");

                      

                                                                                                if (o != null) {                                                                                                                      

                                                                                                                

                                                                                                                if(o.Value!=null && o.Value!="")

                                                                                                                                item.nodeColourRegex = o.Value;                                                                                           

                                                                                                                else

                                                                                                                                flag=false;

                        }

                                                                                                                

                                                                                                o = findCourse(course.children[2], "AttributeType");

                       

                                                                                   if (o != null) {                                                                                                                   

                                                                                                                

                                                                                                                if(o.Value!=null && o.Value!="")

                                                                                                                                item.attributeType3 = o.Value;                                                                                 

                                                                                                                else

                                                                                                                                flag=false;

                        }

                        

                        o = findCourse(course.children[2], "NavigationStrategyComponentAlias");

                      

                                                                                                if (o != null) {                                                                                                                      

                                                                                                                

                                                                                                                if(o.Value!=null && o.Value!="")

                                                                                                                                item.navigationStrategyComponentAlias = o.Value;                                                                                        

                                                                                                                else

                                                                                                                                flag=false;

                        }

                                                                                                

                        o = findCourse(course.children[2], "Value");

                      

                                                                                                if (o != null) {                                                                                                                      

                                                                                                                

                                                                                                                if(o.Value!=null && o.Value!="")

                                                                                                                                item.value = o.Value;                                                                                     

                                                                                                                else

                                                                                                                                flag=false;

                        }

                                                                                                

                                                                                                o = findCourse(course.children[3], "FilterComponentOperatorType");

                      

                                                                                                if (o != null) {

                                                                                                                                

                                                                                                                

                                                                                                                if(o.Value!=null && o.Value!="")

                                                                                                                                item.operator = o.Value;                                                                                              

                                                                                                                else

                                                                                                                                flag=false;

                        }

                                                                                                

                                                                                                if (flag)

                                                                                                                dg.dataProvider.addItem(item);

                                                                                                else

                                                                                                                Alert.show("Please Enter Required Values.");

                    }

                    

                }               

                

            }

            

            private function findCourse(parent:Object, name:String):Object{

                var a:Array = treeDg.mx_internal::rendererArray;

                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:Script>

    <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"

                             defaultLeafIcon="{null}"

                             folderOpenIcon="{null}"

                             folderClosedIcon="{null}">

            <mx:dataProvider>

                <mx:HierarchicalData source="{student}" />

            </mx:dataProvider>

            <mx:groupItemRenderer>

                <mx:Component>

                    <mx:AdvancedDataGridGroupItemRenderer width="100%">

                        <mx:Script>

                            <![CDATA[

                                import mx.collections.HierarchicalCollectionView;

                                import mx.controls.AdvancedDataGrid;

                                import mx.controls.Button;

 

                                private var button:Button;

 

                                override protected function createChildren():void

                                {

                                    super.createChildren();

                                    button = new Button();

                                    button.label = "+";

                                    button.width = 35;

                                    button.height = 22;

                                    button.addEventListener(MouseEvent.CLICK, addAttributeType);

                                    addChild(button);

                                }

 

                                private function addAttributeType(event:MouseEvent):void{

                                    var dp:HierarchicalCollectionView = outerDocument.treeDg.dataProvider as HierarchicalCollectionView;

                                    dp.addChild(data, {Course:"ClusterBy", children:[

                            {Course:"AttributeType", Boys:120, TotalStudent:180, PASSinper:98.0, FAILinper:2.0}

                        ]

                        });

                                }

 

                                override public function set data(value:Object):void{

                                    super.data = value;

                                    if(data != null){

                                        button.visible = (data.showButtons == true);

                                    }

                                }

                                

                                override protected function updateDisplayList(unscaledWidth:Number,

                                                                              unscaledHeight:Number):void

                                {

                                    super.updateDisplayList(unscaledWidth, unscaledHeight);

                                    button.x = unscaledWidth - button.width - 5;

                                }

                            ]]>

                        </mx:Script>

                    </mx:AdvancedDataGridGroupItemRenderer>

                </mx:Component>

            </mx:groupItemRenderer>

            <mx:columns>

                <mx:AdvancedDataGridColumn dataField="Course">

                    <mx:itemRenderer>

                        <mx:Component>

                            <mx:AdvancedDataGridGroupItemRenderer width="100%">

                                <mx:Script>

                                    <![CDATA[

                                        import mx.collections.HierarchicalCollectionView;

                                        import mx.controls.AdvancedDataGrid;

                                        import mx.controls.Button;

                                        

                                        private var button:Button;

                                        

                                        override protected function createChildren():void

                                        {

                                            super.createChildren();

                                            button = new Button();

                                            button.label = "-";

                                            button.width = 35;

                                            button.height = 22;

                                            button.addEventListener(MouseEvent.CLICK, removeAttributeType);

                                            addChild(button);

                                        }

                                        

                                        private function removeAttributeType(event:MouseEvent):void{

                                            var parentItem:Object = AdvancedDataGrid(owner).getParentItem(data);

                                                                                                                                                                                var parentItem1:Object = AdvancedDataGrid(owner).getParentItem(parentItem);

                                            var dp:HierarchicalCollectionView = AdvancedDataGrid(owner).dataProvider as HierarchicalCollectionView;

                                            dp.removeChild(parentItem1, parentItem);

                                        }

                                        

                                        override public function set data(value:Object):void{

                                            super.data = value;

                                            if(data != null){

                                                button.visible = (data.Course == 'AttributeType');

                                            }

                                        }

                                        

                                        override protected function updateDisplayList(unscaledWidth:Number,

                                                                                      unscaledHeight:Number):void

                                        {

                                            super.updateDisplayList(unscaledWidth, unscaledHeight);

                                            button.x = unscaledWidth - button.width - 5;

                                        }

                                    ]]>

                                </mx:Script>

                            </mx:AdvancedDataGridGroupItemRenderer>

                        </mx:Component>

                    </mx:itemRenderer>

                </mx:AdvancedDataGridColumn>

                <mx:AdvancedDataGridColumn dataField="Value"> 

                    <mx:itemRenderer>

                        <mx:Component>

                            <mx:Canvas width="100%">

                                <mx:Script>

                                    <![CDATA[

                                        override public function set data(value:Object):void{

                                            super.data = value;

                                            if(data != null)

                                                ti.text = data.Value;

                                        }

                                        

                                        private function setValue(event:Event):void{

                                            if(data != null)

                                                data.Value = event.target.text

                                        }

                                    ]]>

                                </mx:Script>

                                <mx:TextInput id="ti" visible="{data.hasOwnProperty('Boys')}" width="98%" change="setValue(event)"/>

                            </mx:Canvas>

                        </mx:Component>

                    </mx:itemRenderer>

                </mx:AdvancedDataGridColumn>

            </mx:columns>

        </mx:AdvancedDataGrid>

        <mx:HBox width="100%" horizontalAlign="right" paddingRight="10" paddingBottom="10">

            <mx:Button label="Add" click="add()"/>

        </mx:HBox>

        <mx:DataGrid id="dg" horizontalCenter="0" verticalCenter="0" dataProvider="[]">

            <mx:columns>

                <mx:DataGridColumn dataField="attributeType" headerText="AttributeType"/> 

                <mx:DataGridColumn dataField="clusterAggregateFunction" headerText="ClusterAggregateFunction" width="150"/> 

                <mx:DataGridColumn dataField="attributeType2" headerText="AttributeType" />

                <mx:DataGridColumn dataField="nodeColourRegex" headerText="NodeColourRegex"/>

                <mx:DataGridColumn dataField="navigationStrategyComponentAlias" headerText="NavigationStrategyComponentAlias"/> 

                                                                <mx:DataGridColumn dataField="attributeType3" headerText="AttributeType"/> 

                <mx:DataGridColumn dataField="value" headerText="Value"/>

                                                                <mx:DataGridColumn dataField="operator" headerText="Operator"/>                

            </mx:columns>

        </mx:DataGrid>

        <mx:ControlBar>

            <mx:Spacer width="80%"/>

            <mx:Button paddingRight="20" label="Save" click="save()"/>

        </mx:ControlBar>

    </mx:Panel>

</mx:Application>

Open in new window

Filter.bmp
0
alamflex
Asked:
alamflex
  • 3
1 Solution
 
dgofmanCommented:
Why do you want to use FORM container instead using datagrid rows?
0
 
dgofmanCommented:
And if you will add attributes how you will delete later and assign additional parameters

 Boys:???, TotalStudent:???, PASSinper:???, FAILinper:???
0
 
alamflexAuthor Commented:
Here we need to add multiple values and the client wants like this kind of UI. So that user can add mulitple values and can delete the values by using (-) delete button dynamically.I think you got my point.

 Boys:???, TotalStudent:???, PASSinper:???, FAILinper:???

Reg this as of now we are using only Boys in our sample code i guess rest not required.

0
 
dgofmanCommented:
Please look on Adobe example of AdvancedDataGrid with chart (last one)

http://livedocs.adobe.com/flex/3/html/help.html?content=advdatagrid_10.html

Do you want to replace chart by mx:Form or something different I couldn’t understand your requirements

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now