tags:

views:

187

answers:

1

I have a DataGrid wired to backend with one field/column as STATUS. The DG uses both CheckBox HeaderRenderer and itemRenderer. When STATUS is "fail", I want to show the checkbox and when it's anything else, not show it (or, as a compromise, disable it). The visible property has no effect whatever (I don't know why) since the checkbox always shows and the enabled=false simply greys it out but still allows the headerRenderer to check & uncheck (again, don't know why). Any idea why this is happening??? Code is quite simple:

itemRenderer -

<?xml version="1.0" encoding="utf-8"?>
<mx:CheckBox xmlns:mx="http://www.adobe.com/2006/mxml"&gt;

<mx:Script>
<![CDATA[
    import com.fidelity.ORWS.view.requests.RequestStatus;
    import mx.controls.Alert;

    override public function set data(value:Object):void
    {
    super.data = value;
    this.selected = false;

    if(data.status == 'SUCCESS' || data.status == 'PROCESSING')
        { this.enabled = false; }           
    }
]]>
</mx:Script>
</mx:CheckBox>

HeaderRenderer -

<?xml version="1.0" encoding="utf-8"?>
<mx:CheckBox xmlns:mx="http://www.adobe.com/2006/mxml"&gt;
<mx:Script>
<![CDATA[
    import mx.collections.ArrayCollection;
    import mx.controls.DataGrid;

    override protected function clickHandler(event:MouseEvent):void
    {
    super.clickHandler(event);

    var dg:DataGrid = this.owner as DataGrid;
    var dp:ArrayCollection = dg.dataProvider as ArrayCollection;
    var cb:requestcheckboxRenderer;

    for ( var i:int=0;i<dp.source.length;i++)
    {
    cb = dg.indexToItemRenderer(i) as requestcheckboxRenderer;
    cb.selected = ( selected ) ? true : false;
    }
    }
]]>
</mx:Script>
</mx:CheckBox>
+1  A: 

The visible property won't work because the datagrid itself makes its renderers visible and invisible when it adds or removed them. If you want to hide the checkbox, you either have to change the headerrenderer of the datagrid to something else the moment you hide it, or change your HeaderRenderer to be a container (a VBox or whatever) that contains the checkbox. Then you can set the visible property of the checkbox, which will be different from the visible property of the header renderer.

For the checkbox even working when you set it enabled=false, that is probably because you are overriding clickHandler. That one is apparently still called when it is clicked, and that makes sense (it's not because the component is disabled that clicks don't happen anymore). You should instead catch the changing of the checkbox in another way. For example, add an event listener on the change event.

Wouter Coekaerts
Thanks -Finally did get it to work. Basically wrapping checkbox in a container which allowed an id on the checkbox and was able to hide/show. This was the preferred solution anyway so the enable/disable was no longer a concern.Thanks again...
dude22