簡體   English   中英

在 flex 4 的 AIR 應用程序中更改特定條件下數據網格行的文本顏色

[英]Change the text color of a datagrid row on particular condition in AIR application in flex 4

我想在特定條件下更改數據網格行的文本顏色,即。 我正在檢查一個條件。如果滿足,那么我必須更改每個單元格的文本顏色,即整行。

這是代碼,

private function resultHandlerGrid(event:ResultEvent):void{     

    arrc1 = ArrayCollection(event.result);

    adg1.addEventListener(  ListEvent.ITEM_CLICK,getValue);

    }
private function getValue(e:ListEvent):void{



if(e.itemRenderer.data.priority == "High")
{           

 e.itemRenderer.data.client_name.setStyle('color',0xFF0000);

 }
}

此行拋出錯誤:setStyle is not a function

e.itemRenderer.data.client_name.setStyle('color',0xFF0000);

我將在自定義 ItemRenderer 中執行此操作,並通過覆蓋set dataupdateDisplayList function 來設置字體顏色。

這篇文章

應用程序:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/ -->
<mx:Application name="DataGridColumn_itemRenderer_test "
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.controls.dataGridClasses.DataGridColumn;
            import mx.utils.ObjectUtil;

            private function price_labelFunc(item:Object, column:DataGridColumn):String {
                return currencyFormatter.format(item.@price);
            }

            private function price_sortCompareFunc(itemA:Object, itemB:Object):int {
                return ObjectUtil.numericCompare(itemA.@price, itemB.@price);
            }
        ]]>
    </mx:Script>

    <mx:XML id="itemsXML">
        <items>
            <item name="Item 1" price="1.32" />
            <item name="Item 2" price="-12.23" />
            <item name="Item 3" price="4.96" />
            <item name="Item 4" price="-0.94" />
        </items>
    </mx:XML>

    <mx:Style>
        .centered {
            text-align: center;
        }
    </mx:Style>

    <mx:CurrencyFormatter id="currencyFormatter"
            precision="2"
            useNegativeSign="false" />

    <mx:DataGrid id="dataGrid" dataProvider="{itemsXML.item}">
        <mx:columns>
            <mx:DataGridColumn dataField="@name"
                    headerText="Name:"
                    headerStyleName="centered" />

            <mx:DataGridColumn dataField="@price"
                    headerText="Price:"
                    textAlign="right"
                    headerStyleName="centered"
                    labelFunction="price_labelFunc"
                    sortCompareFunction="price_sortCompareFunc"
                    itemRenderer="PriceLabel" />
        </mx:columns>
    </mx:DataGrid>

</mx:Application>

PriceLabel.as:

/** http://blog.flexexamples.com/2007/08/20/formatting-a-flex-datagrid-control-using-a-custom-item-renderer/ */
package {
    import mx.controls.Label;
    import mx.controls.listClasses.*;

    public class PriceLabel extends Label {

        private const POSITIVE_COLOR:uint = 0x000000; // Black
        private const NEGATIVE_COLOR:uint = 0xFF0000; // Red

        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
            super.updateDisplayList(unscaledWidth, unscaledHeight);

            /* Set the font color based on the item price. */
            setStyle("color", (parseFloat(data.@price) <= 0) ? NEGATIVE_COLOR : POSITIVE_COLOR);
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM