2
votes

Unless I'm missing something obvious here, there is no way of disbabling one or more rows in a DataGrid. I would expect a disabledRows or disabledRowIndidices property on the DataGrid or List component but that doesn't seem to exist.

I found a "rendererArray" property which is scoped to mx_internal and contains all itemrenderers of all cells in the datagrid. So I can check the type and the value of the data inside the renderer and enable or disable all cells of the same row, but that feels too much like a hack.

Any suggestions?

Edit: I realize that disabling a row could mean different things. In my case it means not being able to edit the row even when the editable property of the datagrid is set to true. It could however also mean not being able to select a row, but that's not what I'm looking for.

4
What does being disabled mean to a datagrid row? - inferis
I my case it means not being able to edit it. It could however also mean not being able to select a row. Good remark, I'll update the question. - Christophe Herreman
Also, datagrids aren't defined by their rows, they're defined by columns. For disabling certain rows, you're talking about knowing about the underlying data, which means handling it in the itemRenderers. - inferis

4 Answers

6
votes

To do this you will need some data for that row to signify that it is uneditable. Then when the "itemEditBeginning" then check the data or row index to enable/disable the default behavior with event.preventDefault ...

public function preventEditing(event:DataGridEvent):void
{   
    var status : Boolean = ArrayObjs[rowIndex].isYourCondition;

    if (status == true)
    {
        event.preventDefault();
    }
}

The other option is to make a custom ItemRenderer for your data cell but don't think that is what you want as you would need to make it for each of your cells.

2
votes

actually this is best done via "itemEditBeginning". Look here for a good tutorial: link text

0
votes

Alex Harui provides a good example with source here, http://blogs.adobe.com/aharui/2007/06/disabling_list_selection.html It's a bit of a lengthy solution, but covers mouse and keyboard interaction with the datagrid. I agree with you, it's surprising that there isn't a "built-in" method to do this.

0
votes

Just set a function to the "itemEditBegin"of the DataGrid that does something like this:

protected function validateEdition(event:DataGridEvent):void{
    if([EDITION CRITERA NOT MET]){
          event.preventDefault();
    }
}

<mx:DataGrid id="grid" itemEditBegin="validateEdition(event)" editable="true">
      <mx:columns>
         [[YOUR COLUMN CONFIGURATION]]
      </mx:columns>
</mx:DataGrid> 

event.preventDefault() will stop the DataGrid from switching the ItemRenderer to the ItemEditor for so stopping the edition of the row that doesn't meet the criteria. Your DataGrid must be editable for this to Work.

This should do the trick.