views:

6685

answers:

4

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.

A: 

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.

Michael Prescott
+1  A: 

Hi,

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

+4  A: 

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 ...

function preventEditing(event:DatagridEvent){
  if(event.rowIndex==1) // or check some of your dataprovider info. 
  {  
   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.

AndrewB
A: 

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.

Chepech