在 Flex 4 的 AIR 应用程序中根据特定条件更改数据网格行的文本颜色

发布于 2024-11-10 05:03:01 字数 576 浏览 3 评论 0原文

我想在特定条件下更改数据网格行的文本颜色,即。 我正在检查一个条件。如果满足,那么我必须更改每个条件的文本颜色 单元格,即整行。

这是代码,

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 不是函数

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

I want to change the text color of the datagrid row on particular condition ie.
i am checking on a condition.If that satisfies then I have to change the text color of each
cell ie the whole row.

Here is the code,

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);

 }
}

This line is throwing error: setStyle is not a function

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁把谁当真 2024-11-17 05:03:01

我将在自定义 ItemRenderer 中执行此操作,并通过覆盖 set dataupdateDisplayList 函数来设置字体颜色。

来自这篇文章

应用程序:

<?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);
        }
    }
}

I would do this in a custom ItemRenderer and set the font color by overriding the set data or updateDisplayList function.

From this article:

The application:

<?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);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文