Changing the text color in my Flex DataGrid

Posted on 2009-02-19
Last Modified: 2013-11-11

I have a DataGrid that is populated from a datasource. In one of the columns, I only have 2 entries: "Increased" and "Decreased". If the value is decreased, I want to change the color text to "red" and if the value is "increased", I want to change the color value to "green".

I would like to do this in action script and after looking online for 2 hours, I found nothing that actually works. Can I ask you to please give me a sample *.mxml file and maybe even an *.xml file that works that I can play with?

Any help is greatly appreciated. Thanks!
Question by:piyushdabomb
    LVL 1

    Accepted Solution

    This MXML should give you enough clues to adjust to you needs i hope :-)
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="" layout="absolute">
    			[Bindable] private var xmlData:XML =
    					<value increased="true">53</value>
    					<value increased="false">38</value>
    	<mx:DataGrid x="20" y="20" id="valuesDataGrid" dataProvider="{xmlData.value}">
    			<mx:DataGridColumn headerText="Values">
    						<mx:Text text="{data}" color="{(data.@increased == 'true') ? 0x00FF00 : 0xFF0000 }" paddingLeft="5" />

    Open in new window

    LVL 19

    Expert Comment

    Gotta love ternaries.

    Author Closing Comment


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
    While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
    The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
    The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now