开发者

Format Rows of Datagrid differently in Flex 4

开发者 https://www.devze.com 2023-04-01 00:09 出处:网络
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 a

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:M开发者_如何学GoXDataGridItemRenderer>

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'}"


Custom renderer can be created by implementing IDataRenderer, IDropInListItemRenderer.

ManageFilterValueEditor extends VBox implements IDataRenderer, IDropInListItemRenderer

This gives access to _listdata and _data. List data represents row. in setData we can access the row as

override public function set data(value:Object):void {
            _data = value;
            if(_listData!=null){
                     var col:DataGridColumn=((_listData.owner as DataGrid).columns[_listData.columnIndex] as DataGridColumn);
                    removeAllChildren();

//depending on column, it can be appropriately formatted

0

精彩评论

暂无评论...
验证码 换一张
取 消