OK, so doing the preferredHeight trickis
a bad idea. Unfortunately in looking at the code that builds the row I
basically can’t figure out the “right” thing to do. I think
you should file a bug saying that it’s too difficult to indicate in a
cell renderer that you want to be the same size as the cell itself. http://www.macromedia.com/go/wish.
Here’s the workaround and I can’t
decide if it’s supported or not (so we’ll assume it’s not):
In bgCell instead of the
getPreferredHeight() method use this:
function setSizeNoLayout(w, h) :
Void
{
super.setSizeNoLayout(w,
owner.layoutHeight);
}
HTH,
Matt
From: Andrew Spaulding
[mailto:[EMAIL PROTECTED]
Sent: Thursday, February 03,2005
2:26 PM
To: [email protected]
Subject: [flexcoders] Re: simple
datagrid cell colour renderer
Hi Matt,
I have tried using a getPreferredHeight method
that returns the owners
layoutHeight and this works fine, the colourfills
the entire cell
now. But I still have some weird behaviour when
there is a scoll bar
on my datagrid. If click and drag on the scroll
bar and move it up and
down the list the rows in the datagrid gradually
increase in height.
Do you have any idea what may be causing this?
Andrew.
-----------
Use the following as a demo for this behaviour:
App.mxml
<?xml version="1.0"
encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
xmlns="*">
<mx:DataGrid
variableRowHeight="true"
dataProvider="{[{foo: 'bar', doo: 'This is some sample text'},
{foo: 'bar'}, {foo: 'baz', doo: 'This is some
sample text, this is
some sample text'}, {foo: 'bar', doo: 'This is
some sample text'},
{foo: 'bar'}, {foo: 'baz', doo: 'This is some
sample text, this is
some sample text'},{foo: 'bar', doo: 'This is some
sample text'},
{foo: 'bar'}, {foo: 'baz', doo: 'This is some
sample text, this is
some sample text'},{foo: 'bar', doo: 'This is some
sample text'},
{foo: 'bar'}, {foo: 'baz', doo: 'This is some
sample text, this is
some sample text'},{foo: 'bar', doo: 'This is some
sample text'},
{foo: 'bar'}, {foo: 'baz', doo: 'This is some
sample text, this is
some sample text'},{foo: 'bar', doo: 'This is some
sample text'},
{foo: 'bar'}, {foo: 'baz', doo: 'This is some
sample text, this is
some sample text'},{foo: 'bar', doo: 'This is some
sample text'},
{foo: 'bar'}, {foo: 'baz', doo: 'This is some
sample text, this is
some sample text'},{foo: 'bar', doo: 'This is some
sample text'},
{foo: 'bar'}, {foo: 'baz', doo: 'This is some
sample text, this is
some sample text'}]}">
<mx:columns>
<mx:Array>
<mx:DataGridColumn columnName="foo"
cellRenderer="bgCell" />
<mx:DataGridColumn columnName="doo" wordWrap="true"
/>
</mx:Array>
</mx:columns>
</mx:DataGrid>
</mx:Application>
bgCell.mxml
<?xml version="1.0"
encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.macromedia.com/2003/mxml">
<mx:Script>
<![CDATA[
var
value : String;
var
owner;
function setValue(v) : Void
{
value = v;
setStyle("backgroundColor", v == 'baz' ? 0xff0000 :
undefined);
}
function getPreferredHeight() : Number
{
return owner.layoutHeight;
}
]]>
</mx:Script>
<mx:Label
text="{value}" />
</mx:VBox>
--- In [email protected],
Matt Chotin <[EMAIL PROTECTED]>
wrote:
> OK, try adding this to the cell renderer:
>
>
>
>
var owner;
>
>
function getPreferredHeight() : Number
>
>
{
>
>
return owner.layoutHeight;
>
>
}
>
>
>
> Matt
>
>
>
> _____
>
> From: Andrew Spaulding [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, February 02, 2005 9:06PM
> To: [email protected]
> Subject: [flexcoders] Re: simple datagrid
cell colour renderer
>
>
>
>
> Here's some sample code to demonstrate what
I'm talking about. You can
> see that the problem in the last row ofthe
grid.
>
>
> App.mxml
> <?xml version="1.0"
encoding="utf-8"?>
>
> <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml
> <http://www.macromedia.com/2003/mxml>
"
> xmlns="*">
>
> <mx:DataGrid
variableRowHeight="true"
>
dataProvider="{[{foo: 'bar', doo: 'This is some sample text'},
> {foo: 'bar'}, {foo: 'baz', doo: 'This is some
sample text, this is
> some sample text'}]}">
>
>
<mx:columns>
>
>
<mx:Array>
>
>
<mx:DataGridColumn columnName="foo"
> cellRenderer="bgCell" />
>
<mx:DataGridColumn columnName="doo" wordWrap="true"
/>
>
>
</mx:Array>
>
>
</mx:columns>
>
> </mx:DataGrid>
>
> </mx:Application>
>
>
> bgCell.mxml
> <?xml version="1.0"
encoding="utf-8"?>
>
> <mx:VBox xmlns:mx="http://www.macromedia.com/2003/mxml
> <http://www.macromedia.com/2003/mxml>
">
>
> <mx:Script>
>
<![CDATA[
>
>
var value : String;
>
>
function setValue(v) : Void
>
>
{
>
value = v;
>
>
setStyle("backgroundColor", v == 'baz' ? 0xff0000 :
> undefined);
>
}
>
>
]]>
> </mx:Script>
>
> <mx:Label
text="{value}" />
>
> </mx:VBox>
>
>
> Andrew.