I am using the following itemrenderer in one of the column of my datagrid. However I want to format each row of the datagrid differently. The column consists of numbers but some need to be formatted as Numbers while others as currency etc. Also note that I have an additional column which consists of 0 and 1 where 0 means that it should be formatted as Number and 1 means that it should be formatted as Currency.
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true">
<s:Label id="lblData" top="0" left="0" textAlign="center" verticalAlign="middle" right="0" bottom="0" text="{dataGridListData.label}" backgroundColor="#EDFB09"/>
<s:Rect left="0" right="0" top="0" bottom="0">
<s:stroke>
<s:SolidColorStroke color="0x000000" weight="1"/>
</s:stroke>
</s:Rect>
<fx:Script>
<![CDATA[
]]>
</fx:Script>
</s:MXDataGridItemRenderer>
Any help upon how I can implement such a function, am trying to use dataGridListData.label in a function in the itemrenderer but it gives error.
Help Thanks
Well the dataGridListData object should allready contain all information you need: columnIndex, rowIndex, dataField.
In simple cases, the usage of the "elvis-operator" (? as shorthand of an if-statement) comes in really handy:
(condition) ? true-block: else-block
Some examples: color="{(dataGridListData.rowIndex % 2 == 0) ? #00ff00 : #0000ff}" (For alternating row colors) text="{(dataGridListData.dataField == "coolField") ? 'Coool!': 'Uncool'}"