7 Replies Latest reply on Mar 16, 2010 12:08 AM by Balagopalr

    Datagrid colour change

    Balagopalr

      Hi,

      Can anybody please tell me how to change color of a dynamic value in a data grid.The value has to change colour when a particular value is crossed and change back when value falls below that.Please help me with a sample code so that I can better understand it.

       

      Thanks

      bgr

        • 2. Re: Datagrid colour change
          Balagopalr Level 1

          Thanks for the reply but the code u referred was not working.Can u just help me regarding this.I just want to a grid value(dynamic one) to change colour when the value crosses a threshold value and change back colour when the value falls down.Please can u give me a simple code for this so that i can work on it

          • 3. Re: Datagrid colour change
            Arun Lal Level 2

            <mx:DataGrid id="dg" dataProvider="{dgArr}" x="262" y="111">

             

                    <mx:columns>

             

                        <mx:DataGridColumn dataField="uid"/>

             

                        <mx:DataGridColumn dataField="value">

             

                            <mx:itemRenderer>

             

                                <mx:Component>

             

                                    <mx:TextArea height="22" selectable="false" creationComplete="init()" >

             

                                    <mx:Script>

             

                                        <![CDATA[

             

                                            private function init():void{

             

                                                if(Number(this.text)>150){

             

                                                    this.setStyle("color","0x0000ff")

             

                                                }else{

             

                                                    this.setStyle("color","0xff0000")

             

                                                }

             

                                            }

             

                                        ]]>

             

                                    </mx:Script>

             

                                    </mx:TextArea>

             

                                </mx:Component>

             

                            </mx:itemRenderer>

             

                        </mx:DataGridColumn>

             

                    </mx:columns>

             

                </mx:DataGrid>

             

                <mx:Script>

             

                    <![CDATA[

             

                        import mx.collections.ArrayCollection;

             

                     

             

                        [Bindable]

             

                        private var dgArr:ArrayCollection = new ArrayCollection([{uid:"1",value:"100"},{uid:"2",value:"200"},{uid:"3",value:"140"},{uid:" 4",value:"320"},{uid:"5",value:"160"}]);

             

                                    

             

                    ]]>

             

                </mx:Script>
            • 4. Re: Datagrid colour change
              Balagopalr Level 1

              Thanks a lot.Worked Perfectly

              • 5. Re: Datagrid colour change
                Balagopalr Level 1

                Hi,

                The above code I used for a dynamic value.The colour in changing but not continuously as the value comes and goes above and below the value.So I tried to add an event listner.But its not working.Can u just say where to add code (listener) so that the colour changes continuously as value goes up an down the threshold value.

                • 6. Re: Datagrid colour change
                  Arun Lal Level 2

                  Write this also:

                   

                  updateComplete="init()"

                  • 7. Re: Datagrid colour change
                    Balagopalr Level 1

                    updateComplete is not working.

                    Only initially the colour is changing.After that the colour is not changing as the value changes.