0 Replies Latest reply on Jun 30, 2009 4:57 PM by Johnking08

    How to access component renderer from AdvancedDataGrid

    Johnking08 Level 1

      I have an AdvancedDataGrid that uses a component renderer: com.my.components.ChangeRenderer.

      When I use the <mx:rendererProvider> in <mx:AdvancedDataGrid> as below, the datagrid is not displayed.

      When I comment off the <mx:rendererProviders> section, the datagrid shows up without the renderer's effect.

      Anything wrong in the code below:

       

      ...

      <mx:AdvancedDataGrid id="quotes" sortExpertMode="true"
                                   sortableColumns="true" dataProvider="{quotesArrayCollection}"
                                   height="100%" width="100%" fontSize="8">
                  <mx:columns>
                      <mx:AdvancedDataGridColumn headerText="Symbol" dataField="Symbol" width="50"/>
                      <mx:AdvancedDataGridColumn headerText="Last Trade Price" dataField="Last Trade Price" width="85"/>
                      <mx:AdvancedDataGridColumn headerText="Last Trade Date" dataField="Last Trade Date" width="85"/>
                      <mx:AdvancedDataGridColumn headerText="Last Trade Time" dataField="Last Trade Time" width="85"/>
                      <mx:AdvancedDataGridColumn id="change" headerText="Change Percent" dataField="Change Percent" width="85"/>
                      <mx:AdvancedDataGridColumn headerText="Open" dataField="Open" width="35"/>
                      <mx:AdvancedDataGridColumn headerText="Day High" dataField="Day High" width="55"/>
                      <mx:AdvancedDataGridColumn headerText="Day Low" dataField="Day Low" width="50"/>>
                  </mx:columns>
                 
                  <mx:rendererProviders>
                      <mx:AdvancedDataGridRendererProvider column="{change}"
                          columnSpan="1" renderer="com.my.components.ChangeRenderer"/>
                  </mx:rendererProviders>

      </mx:AdvancedDataGrid>

      ...

       

      ---------ChangeRenderer.mxml-----

      <?xml version="1.0"?>
      <!-- com/my/components/ChangeRenderer.mxml -->
      <mx:Label xmlns:mx="http://www.adobe.com/2006/mxml" textAlign="center">
          <mx:Script> <![CDATA[
              import mx.controls.Alert;

       

              override public function set data(value:Object):void {   

                  Alert.show("In Renderer ...");
                  var change:String = value["Change Percent"].toString(

                  if (change.charAt(0) == "-") {
                      setStyle("color", "red");
                  }
                  else {
                      setStyle("color", "green");
                  }
                  text = change;
              }
          ]]> </mx:Script>
      </mx:Label>