2 Replies Latest reply on Jul 19, 2011 3:08 PM by Amy Blankenship

    Conditional Formatting Flex 4.5

    GabrielGPP Level 1

      I need to do a conditional formatting similar to Excel, depending on the text that is in a AdvancedDataGrid cell backgroundcolor paint the cell with a certain color, could someone tell me what the best way to do this? Thank you

       

      Could someone pass me an example?

        • 1. Re: Conditional Formatting Flex 4.5
          GabrielGPP Level 1

          Good evening, I managed to find an example in a Flex 3 DataGrid common, I wonder if I have to make any changes to format an AdvancedDataGrid in Flex 4.5.1:

           

          package {
          
              import mx.controls.Label;
              import mx.controls.dataGridClasses.*;
              import mx.controls.DataGrid;
              import flash.display.Graphics;
              import mx.styles.StyleManager;
          
              [Style(name="backgroundColor", type="uint", format="Color", inherit="no")]
              
              public class BackgroundComp extends Label {
          
                  override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
               {
                    super.updateDisplayList(unscaledWidth, unscaledHeight);
                          
                    var g:Graphics = graphics;
                    g.clear();
                    var grid1:DataGrid = DataGrid(DataGridListData(listData).owner);
                    if (grid1.isItemSelected(data) || grid1.isItemHighlighted(data))
                        return;
                    if (data[DataGridListData(listData).dataField] > 15) 
                       {
                        g.beginFill(0xCC0033);
                        g.drawRect(0, 0, unscaledWidth, unscaledHeight);
                        g.endFill();
                    }
               }
              }
          }

          • 2. Re: Conditional Formatting Flex 4.5
            Amy Blankenship Level 4

            AdvancedDataGrid actually has a styleFunction, so it's actually much better than the default DataGrid for this.  The

            problem is that the default AdvanceDataGrid itemRenderer does not allow you to add anything to it--so you may need to write your own itemRenderer and give it custom styles based on what you need.  For full discussion, see

             

            http://flexdiary.blogspot.com/2008/06/musings-on-advanceddatagrid-part-2.html

             

            HTH;

             

            Amy