views:

5773

answers:

2

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.

+3  A: 

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.

seanalltogether
I tried that, but this.width is always 0. I suspect that it is a result of it not having been rendered yet, as it is an HBox with (presumably) 100% width.
Alex
Thanks a bunch, Sean. Never even occurred to me to overwrite the updateDisplayList. +1
Ross Henderson
A: 

Hi Alex, I need to write exactly the same renderer for my grid but I'm new to flex and I don't know how to do this...can you please refer me to a good tutorial or give me an example of your renderer to figure out how to render the grid cell to view the bar chart? thanks in advance!

AngelHeart