im just wondering why you think an ordinary check box wont retain it's selected 
state when scrolling? can you provide an example code that does that? maybe it 
will be more beneficial to approach the problem using that approach. Just a 
thought. 


--- On Sun, 5/25/08, dbronk <[EMAIL PROTECTED]> wrote:
From: dbronk <[EMAIL PROTECTED]>
Subject: [flexcoders] Why is this renderer so slow?
To: flexcoders@yahoogroups.com
Date: Sunday, May 25, 2008, 12:59 AM

I have created a checkbox renderer.  My datagrid has 5 out of 8
 columns that use it.  The datagrid has only about 80 rows it it.  When
 using this renderer the performance of the datagrid is horrible. 
 Scrolling is extremely slow, click a checkbox is extremely slow.  If I
 swap out and use a normal mx:CheckBox for the renderer the performance
 is just fine, but of course that doesn't work as it will not retain
 the state of the checkbox when scrolling.  Here is my code for the
 renderer.  I notice that many of these are re-executed whenever
 anything happens to the datagrid.  That includes just mousing over.

 Thanks.

 Dale

 package renderer
 {
        import flash.events. MouseEvent;

        import mx.controls. CheckBox;

        import spectrumk12. minerva.util. BaseEvent;
        import spectrumk12. minerva.util. Utils;

        [Event(name= "selectionSet" , type="util.BaseEven t")]
        public class RendererCheckBoxXML extends CheckBox
        {
                private var _xmlItem : XML;    //holds the current item xml node
                private var count:int=0;
                private var debug:String= "";

                /** The attribute in the xml to use to store the selected state 
of
 this checkbox. */
                [Inspectable( default=" rendererSelected ")]
                public var selectedAttribute : String = "rendererSelected" ;

                /** The default selection state (true/false) to give if the
 selectedAttribute is not there or null */
                [Inspectable( default=" false", enumeration= "true,false" )]
                public var defaultSelectedStat e : Boolean = false;

                public function RendererCheckBoxXML ()
                {
                        super();
                        trace("RendererChec kBoxXML:Construc tor");
                        this.addEventListen er(MouseEvent. CLICK, onClick, 
false, 0, true);
                }

                // Sets the state of the checkbox based on the selectedAttribute
 attribute.
                override public function set data(oItem:Object) : void
                {
                        _xmlItem = XML(oItem);
                        trace("RendererChec kBoxXML:set data: " + [EMAIL 
PROTECTED]) ;
                        var bSelected : Boolean = false;
                        var attrSelected : String = [EMAIL PROTECTED] 
Attribute] ;
                        this.selected = ( Utils.nullOrBlank( attrSelected) ?
 defaultSelectedStat e : (attrSelected == "true") ); 
                }

                override public function get data() : Object
                {
                        trace("RendererChec kBoxXML:get data: " + (_xmlItem != 
null ?
 [EMAIL PROTECTED] : "null"));
                        return _xmlItem;
                }

                /**
                 * This overridden function is where the logic is for updating 
the xml.
                 */
                override public function set selected(selectedFl ag:Boolean) : 
void
                {
                        trace("RendererChec kBoxXML:set selected: " + [EMAIL 
PROTECTED]) ;
                        super.selected = selectedFlag;

                        // Only update the xml if it needs to be updated.  Each 
time the xml
                        // is updated it will fire any bindings to it so we 
want to keep these
                        // to a minimum.
                        if ( [EMAIL PROTECTED] Attribute] != selectedFlag )
                        {
                                // The selected flag is different than the 
selectedAttribute
 attribute.
                                // Now we make one last check to see if the 
selectedFlag is false and
                                // there is no attribute selectedAttribute.  If 
this is the case, then
                                // we do NOT update because having no attribute 
selectedAttribute will
                                // default to a false.  Again, we do this so 
that we update the xml as
                                // infrequently as possible.
                                if ( selectedFlag || [EMAIL PROTECTED] 
Attribute] .length() > 0 )
                                {
                                        [EMAIL PROTECTED] Attribute] = 
String(this. selected) ;         //set the
 checkbox state into the dataProvider
                                }
                        }
                        dispatchEvent( new BaseEvent("selectio nSet", 
selectedFlag) );
                }

                // Called by click of the checkbox
                private function onClick(mouseEvent: MouseEvent) : void
                {
                        trace("RendererChec kBoxXML:onClick: " + [EMAIL 
PROTECTED]) ;
                        // Simply need to trigger the set selected function as 
that is
 where the logic for updating the xml is.
                        this.selected = this.selected; 
                }

        }
 }

              


      

Reply via email to