Actionscript – Flex dataGrid itemRenderer, access cell width and height

actionscriptapache-flexdatagriditemrenderer

When writing a custom itemRenderer, how do you reference the height and width of the grid cell that it will be rendered in? In such a way that it will resize correctly when the grid is resized.

I am writing a dataGrid itemRenderer that draws a bar graph in the final column of a table.

I have tried referencing 'this', 'this.parent', and a few other things with no success.
My interim hack solution is to add this data to the datacollection, but this wont work when the grid changes size, so I will have to edit it every time.

Best Answer

All flex components including cell renderers are aware of their own widths and heights, so you should be able to just access this.width and this.height

If you're looking for events that tell you when a cell has resized you can listen to the ResizeEvent.RESIZE event or override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void on the component.