Skip to main content
Inspiring
April 9, 2009
Answered

Advanced DataGrid and CheckBoxes.. how to enable/disable dynamically

  • April 9, 2009
  • 1 reply
  • 10726 views

I have an advanced data grid.  I'm using a checkbox as an itemRenderer in one column.  I want to be able to enable or disable the ability to edit the check box, based on the user's role which is not known until the login process completes.

If name the column and do a myColumn.enabled = false, the check box can still be check or unchecked by the user.   This appears to be some sort of 'it is already rendered' problem or something.

<mx:AdvancedDataGrid dataProvider="{myData}"  itemClick="myDG_itemClick(event)"  id="adgMyGrid">
        <mx:columns>

            <mx:AdvancedDataGridColumn width="10" id="adgColumn" editable="false" visible="true"  sortable="false"   dataField="myData" itemRenderer="mx.controls.CheckBox" />  
        </mx:columns>
    </mx:AdvancedDataGrid>

Using the above, I would assume that the adgColumn should not be editable.  But it remains editable, no matter if I try to set it in code or in the declaration.  What am doing wrong?

    This topic has been closed for replies.
    Correct answer

    You need to have a data field that specifies whether or not user should be able to change the state of the CheckBox. So upon login, modify the ADG data provider. And reference the data provider field for the CheckBox enabled field.

    1 reply

    Participant
    April 9, 2009

    The column's editable property specifies whether or not the grid should switch from that column's itemRenderer to the itemEditor when a cell in that column gets focus.  The problem lies in that you're using an editable control as the itemRenderer instead of the itemEditor.  If you want the checkbox look for your renderer, just disabled you can do something like this:

    <mx:AdvancedDataGrid dataProvider="{myData}"  itemClick="myDG_itemClick(event)"  id="adgMyGrid">
         <mx:columns>
              <mx:AdvancedDataGridColumn width="10" id="adgColumn" editable="false" visible="true"  sortable="false"   dataField="myData" itemEditor="mx.controls.CheckBox">

                   <itemRenderer>

                        <mx:Component>

                             <mx:CheckBox enabled="false"/>

                        </mx:Component>

                   </itemRenderer>

              </mx:AdvancedDataGridColumn>

         </mx:columns>

    </mx:AdvancedDataGrid>

    jonporAuthor
    Inspiring
    April 9, 2009

    Well, thank you for that.  That does work to disable the checkbox and corrects my understanding a bit.

    But how do you then enable it?  I need to do it dynamically (code wise), based on user credentials.

    Correct answer
    April 9, 2009

    You need to have a data field that specifies whether or not user should be able to change the state of the CheckBox. So upon login, modify the ADG data provider. And reference the data provider field for the CheckBox enabled field.