Hi, I am trying to change the color of the entire
single row of a datagrid using cellRenderer. I don’t have much experience
using CellRenderer or RowRenderer and have not seen any example where a
cellRenderer changes the property or backgroundColor of entire row. The CellRenderer
setValue() below gives me “[Fault] recursion_limit”. If
anybody has working example to achieve this would be really helpful. function
setValue(str:String, item:Object, sel:Boolean) : Void
{
text = String(item.Price);
var price:Number = Number(text);
if(price > 100)
{
listOwner.dataProvider.editField(getCellIndex().itemIndex,
"backgroundColor", "0x00FFFF");
}
} else …… Thanks, From: listOwner.dataProvider.editField(getCellIndex().itemIndex,
“backgroundColor”, 0x00ffff) Matt From: Thanks Matt, I was under the impression that when
datagrid sort, will clean itself off. Using the same example how I can make the
cellRenderer change the color of entire row where Price > 100? I did tried
using listOwner[getCellIndex().itemIndex].setStyle("backgroundColor",
0x00FFFF) with no luck. Thanks, Shahn From: Well you still need an else so that you
call setBackgroundColor even when price is less than 100. The cell is
re-used, you need to cover all cases in your setValue function. So your
else statement here can be to setCellBackgroundColor(0xffffff, 0) Matt From: Hi Matt, The code is not the problem here. I am not
sure if I have to reassign the dataprovider after I click on Price header. I
replaced the script so now I am just checking for Price > 100 and when you
sort by price after it renders the result is still the same. <mx:Script>
<![CDATA[
function setValue(str, item, sel)
{
text = String(item.Price);
var price:Number = Number(text);
if(price > 100)
{
setCellBackgroundColor(0x00FF00, 100);
}
}
function setCellBackgroundColor(newColor, newAlpha)
{
setStyle("backgroundAlpha", newAlpha==undefined ? 0 :newAlpha);
setStyle("backgroundColor", newColor);
}
]]> </mx:Script> From: Don’t you need a check for < 1000
in your if (price > 100) test? From: Hi, I am using a cellRenderer in my datagrid. Now when I sort by
clicking on header the DatagridColumns on which I have cellRenderer never
cleans up the cell which was rendered by cellRenderer. How can I solve this
issue? Files and screen Image below. <!—Application à <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"> <mx:DataGrid id="myGrid" width="350"
height="100">
<mx:columns>
<mx:Array>
<mx:DataGridColumn columnName="Artist"/>
<mx:DataGridColumn columnName="Price"
cellRenderer="SimpleCustomCellRenderer"/>
<mx:DataGridColumn columnName="Album" />
</mx:Array>
</mx:columns>
<mx:dataProvider>
<mx:Array id="arr">
<mx:Object Artist=" Kapil" Album="All Time Favourites"
Price="101"/>
<mx:Object Artist=" Kapil" Album="Classic Songs"
Price="10"/>
</mx:Array>
</mx:dataProvider>
</mx:DataGrid> </mx:Application> <!—CellRendererà <mx:TextInput
xmlns:mx="http://www.macromedia.com/2003/mxml" borderStyle="none"
backgroundAlpha="0"> <mx:Script> function
setValue(str, item, sel)
{
text = String(item.Price);
var price:Number = Number(text);
if(price > 100)
{
setCellBackgroundColor(0x00FF00, 100);
}
else if(price > 1000)
{
setCellBackgroundColor(0x00FF00, 100);
} } function
setCellBackgroundColor(newColor, newAlpha) {
setStyle("backgroundAlpha", newAlpha==undefined ? 0 :newAlpha);
setStyle("backgroundColor", newColor); } </mx:Script> </mx:TextInput> After Sorting on Price Thanks, Shahn
|