Updating the dataprovider is costly. Make sure it only happens when
required (that is isn't happening during scrolling), and maybe avoid
dispatching an event to do it.  I'm not sure who's listening and what
they will do in response.  If you change the dataprovider, the DataGrid
will do a lot of work.

 

XML is much slower than objects, so it may pay to convert to object.

 

Button already has logic for handling a selectedField in a dataprovider
item.  Since CheckBox inherits from button, you might just be able to
use selectedField, or modify and piggy-back on its timing.

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of dbronk
Sent: Saturday, May 24, 2008 10:00 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Why is this renderer so slow?

 

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.BaseEvent")]
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 defaultSelectedState : Boolean = false;

public function RendererCheckBoxXML()
{
super();
trace("RendererCheckBoxXML:Constructor");
this.addEventListener(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("RendererCheckBoxXML:set data: " + [EMAIL PROTECTED]);
var bSelected : Boolean = false;
var attrSelected : String = [EMAIL PROTECTED];
this.selected = ( Utils.nullOrBlank(attrSelected) ?
defaultSelectedState : (attrSelected == "true") ); 
}

override public function get data() : Object
{
trace("RendererCheckBoxXML: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(selectedFlag:Boolean) : void
{
trace("RendererCheckBoxXML: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] != 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]() > 0 )
{
[EMAIL PROTECTED] = String(this.selected); //set the
checkbox state into the dataProvider
}
}
dispatchEvent(new BaseEvent("selectionSet", selectedFlag));
}

// Called by click of the checkbox
private function onClick(mouseEvent:MouseEvent) : void
{
trace("RendererCheckBoxXML: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