Ted Patrick > { Events & Community } > Adobe Systems


DataGrid CellRenderer V2 Error

There is an error in the V2 DataGrid CellRenderer that makes using components within the dataGrid problematic. Here is the fix.&

In Class "mx.controls.gridclasses.DataGridRow" line 165:


cell._y = (__height-cell._height)/2;


Replace this line with:

if( cell.__height == undefined ){
cell._y = (__height-cell._height)/2;
}else{
cell._y = (__height-cell.__height)/2;
}


The problem was that the cell _y coordinate was based on _height not __height for components. If you added a ComboBox or NumericStepper into a Cell, they would resize incorrectly. The ComboBox would be ok until you opened it and then resized a column. Since the _height of the cell now contains the dropdown list, the _y of the cell is thrown off shooting the cell up aboout 50px. Using __height resolves the issue, but makes it essential to defined a getPreferredHeight function in your cell renderer class.

This makes writing cell renderers for DataGrid much easier allowing just about any component to be inserted, or better many controls in a form.

Cheers and Happy CellRenderering!

Ted ;)

7 Responses to “ DataGrid CellRenderer V2 Error ”

  1. # Blogger Ted Patrick

    If you wanted to get fancy here you could also add in pixel snapping for cell content using Math.round. Cheers, ted ;)  

  2. # Blogger Ted Patrick

    Actually make that Math.floor since that is what is used for the drawing API calls in drawing the background.  

  3. # Anonymous Anonymous

    Yeah, we got this bug for the Flex release, AFAIK. Good catch.

    nig  

  4. # Blogger Ted Patrick

    Thanks Nigel. Cheers, Ted ;)  

  5. # Anonymous Anonymous

    Thanks, this bug was driving me up the wall :)  

  6. # Anonymous Garry Schafer

    Would this be the same as working with a listcomponent? I've got a list that has a cellrenderer with a loader component in it, and it starts off as halfway down the item; upon a rollover it fixes itself.  

  7. # Blogger Ted Patrick

    Gary,

    That sounds like the exact error.

    Ted ;)  

Post a Comment



© 2008 Ted On Flex