4 Replies Latest reply on Aug 11, 2009 4:44 AM by nikos101

    I am going to make a ADG with around 7 columns 6 of which I am going to use checkboxes as Item renderer

    nikos101 Level 2

      I am going to make a ADG with around 7 columns 6 of which I am going to use checkboxes as Item renderers. Each of these 6 checkboxes renderers will be define in separate actionscript files as they will be updating different parts of the ADG data provider. Does this sound like the best option?

        • 1. Re: I am going to make a ADG with around 7 columns 6 of which I am going to use checkboxes as Item renderer
          Gregory Lafrance Level 6

          Hard to say, but it is usually best to try and have your renderers as versatile as possible, so depending on how the renderers will behave differently for each column, in a best case scenario you would have a single renderer class or MXML file that could be used for all the columns, behaving appropriately for each.

           

          Can you describe how the renderers behave differently for the six columns?

           

          If this post answered your question or helped, please mark it as such.

          1 person found this helpful
          • 2. Re: I am going to make a ADG with around 7 columns 6 of which I am going to use checkboxes as Item renderer
            nikos101 Level 2

            Well the only difference is that each checkbox effects a different attribute of the  dataprovider of the ADG:

             

            for example this renderer effects the isSelected attribute. I may want to set a different one , hope this explains it better

             

            package
            {
            import flash.display.DisplayObject;
            import flash.events.KeyboardEvent;
            import flash.events.MouseEvent;
            import flash.text.TextField;
            import mx.controls.CheckBox;
            import mx.controls.advancedDataGridClasses.AdvancedDataGridListData;
            import mx.controls.listClasses.ListBase;

            /**
            *  The Renderer.
            */
            public class CheckBoxRenderer extends CheckBox
            {

                public function CheckBoxRenderer()
                {
                    focusEnabled = false;
                }

                 override public function set data(value:Object):void
                {
                   
                   
                    super.data = value;
                   
                    if(super.data.isSelected == null){
                        data.isSelected = false;
                    }
                   
                    data.isSelected = this.selected;
                   
                    invalidateProperties();
                }
               
                override protected function commitProperties():void
                {
                    super.commitProperties();
                    if (owner is ListBase)
                        selected = ListBase(owner).isItemSelected(data);
                }

                override protected function keyDownHandler(event:KeyboardEvent):void
                {
                }

                override protected function keyUpHandler(event:KeyboardEvent):void
                {
                }

                override protected function clickHandler(event:MouseEvent):void
                {
                      super.clickHandler(event);
                   
                    if(!data.isSelected){
                        data.isSelected = true;
                    }else{
                        data.isSelected = false;
                    }
                }

                override protected function updateDisplayList(w:Number, h:Number):void
                {
                    super.updateDisplayList(w, h);

                    if (listData is AdvancedDataGridListData)
                    {
                        var n:int = numChildren;
                        for (var i:int = 0; i < n; i++)
                        {
                            var c:DisplayObject = getChildAt(i);
                            if (!(c is TextField))
                            {
                                c.x = (w - c.width) / 2;
                                c.y = 0;
                            }
                        }
                    }
                }

            }

            }

            • 3. Re: I am going to make a ADG with around 7 columns 6 of which I am going to use checkboxes as Item renderer
              Gregory Lafrance Level 6

              Hmmm... Now that I see your renderer in action, I think this is more complex.

               

              The problem I see is having different code for each situation in methods like updateDisplayList. It could be that your renderers could be used for multiple fields if the basic datatype or control for the fields are the same.

               

              Hope this helps move along your thinking on this.

              1 person found this helpful
              • 4. Re: I am going to make a ADG with around 7 columns 6 of which I am going to use checkboxes as Item renderer
                nikos101 Level 2

                I went ahead and done a different one for each column, works fine:

                 


                    <mx:AdvancedDataGridColumn headerText="Trade" width="80" editorDataField="tradeList" rendererIsEditor="true" backgroundColor="0xddf5ff">
                                <mx:itemRenderer>
                                    <mx:Component>
                                        <mx:HBox horizontalAlign="center">

                 

                    <mx:Script>
                                                <![CDATA[
                                                    override public function set data(value:Object):void
                                                    {
                                                        super.data=value;
                                                        if(value != null){
                                                        cb1.selected=this.data.trade;
                                                        }
                                                    }
                                                ]]>
                                            </mx:Script>
                                            <mx:CheckBox id="cb1">

                 

                                                <mx:change>
                                                    <![CDATA[
                                                    this.data.isModifiedClientSide = 1;
                                                    this.data.trade = cb1.selected; //used to check through data and update server
                                                    ]]>
                                                </mx:change>
                                            </mx:CheckBox>
                                        </mx:HBox>
                                    </mx:Component>
                                </mx:itemRenderer>

                 

                            </mx:AdvancedDataGridColumn>