3 Replies Latest reply on Apr 14, 2009 6:59 PM by savyasachi

    How to hide itemRenderers in the Grouped rows of an AdvancedDataGrid?

    savyasachi Level 1

      I am using an AdvancedDataGrid and showing a comboBox as the itemRenderer and also the editRenderer. However I am seeing the combobox in the grouped rows also. Below is the code I am using and also attached the screenshot of the app. Please help.

       

      TestAdvGridGrpRen.mxml

      ===================

       

      <?xml version="1.0"?>

      <!-- dpcontrols/adg/SummaryGroupADGCustomSummary.mxml -->

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

       

          <mx:Script>

              <![CDATA[

                  import mx.collections.ArrayCollection;

                  import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;

                  import mx.collections.IViewCursor;   

                  import mx.collections.SummaryObject;

       

      [Bindable]

      private var dpFlat:ArrayCollection = new ArrayCollection([

        {Region:"Southwest", Territory:"Arizona",

            Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},

        {Region:"Southwest", Territory:"Arizona",

            Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000},

        {Region:"Southwest", Territory:"Central California",

            Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000},

        {Region:"Southwest", Territory:"Nevada",

            Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000},

        {Region:"Southwest", Territory:"Northern California",

            Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},

        {Region:"Southwest", Territory:"Northern California",

            Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000},

        {Region:"Southwest", Territory:"Southern California",

            Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},

        {Region:"Southwest", Territory:"Southern California",

            Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}

      ]);

       

                  // Callback function to create

                  // the SummaryObject used to hold the summary data.

                  private function summObjFunc():SummaryObject {

       

                      // Define the object containing the summary data.

                      var obj:SummaryObject = new SummaryObject();

                      // Add a field containing a value for the Territory_Rep column.

                      obj.Territory_Rep = "Alternating Reps";

       

                      return obj;

                  }

       

                  // Callback function to summarizes

                  // every other row of the Actual sales revenue for the territory.

                  private function summFunc(cursor:IViewCursor, dataField:String,

                      operation:String):Number {

       

                      var oddCount:Number = 0;

                      var count:int = 1;

                      while (!cursor.afterLast)

                      {

                          if (count % 2 != 0)

                              oddCount += cursor.current["Actual"];

       

                          cursor.moveNext();

                          count++;

                      }

       

                      return oddCount;

                  }

            ]]>

          </mx:Script>

       

          <mx:AdvancedDataGrid id="myADG"

              width="100%" height="100%"

              initialize="gc.refresh();">      

              <mx:dataProvider>

                  <mx:GroupingCollection id="gc" source="{dpFlat}">

                      <mx:Grouping>

                         <mx:GroupingField name="Region"/>

                         <mx:GroupingField name="Territory">

                            <mx:summaries>

                               <mx:SummaryRow summaryObjectFunction="summObjFunc"

                                  summaryPlacement="first">

                                  <mx:fields>

                                     <mx:SummaryField dataField="Actual" summaryFunction="summFunc"/>

                                  </mx:fields>

                               </mx:SummaryRow>

                            </mx:summaries>

                         </mx:GroupingField>

                      </mx:Grouping>

                  </mx:GroupingCollection>

              </mx:dataProvider>      

       

              <mx:columns>

                  <mx:AdvancedDataGridColumn dataField="Region"/>

                  <mx:AdvancedDataGridColumn dataField="Territory_Rep"

                      headerText="Territory Rep"/>

                  <mx:AdvancedDataGridColumn headerText="Actual" dataField="Actual"

                  rendererIsEditor="true"

                  itemRenderer="TestStatusTypeEditor"

                  editorDataField="type"/>

                  <mx:AdvancedDataGridColumn dataField="Estimate"/>

              </mx:columns>

         </mx:AdvancedDataGrid>

      </mx:Application>

      TestStatusTypeEditor.mxml
      ====================
      <?xml version="1.0" encoding="utf-8"?>
      <mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml"
      creationComplete="OnInit()" >
      <!-- This is the content of the ComboBox.
      <mx:dataProvider>
      <mx:Object label="Cog" />
      <mx:Object label="Sproket" />
      </mx:dataProvider>
      -->
      <mx:Script>
      <![CDATA[
      import mx.collections.ArrayCollection;
              [Bindable]
              public var cards:ArrayCollection = new ArrayCollection(
                  [ {label:"38865", data:1},
                    {label:"29885", data:2},
                    {label:"29134", data:3},
                    {label:"52888", data:4},
                    {label:"38805", data:5},
                    {label:"55498", data:6},
                    {label:"44985", data:7},
                    {label:"44913", data:8}]);
                  
      private function OnInit():void
      {
      dataProvider = cards;
      }
      /**
      * This override of set data compares the data.label against the label property
      * of each item in the dataProvider (above). This code is written a bit more
      * generically than necessary, but it would allow you to have a long list
      * in the dataProvider and not have to change this code.
      */
      override public function set data(value:Object):void
      {
      super.data = value;
      var list:ArrayCollection = dataProvider as ArrayCollection;
      for(var i:int=0; i < list.length; i++)
      {
      if( String(value.statusName) == list[i].label ) {
      selectedIndex = i;
      }
      }
      }
      /**
      * This getter is the one identified as the editorDataField in the list for
      * the itemEditor.
      */
      public function get type() : String
      {
      if( selectedItem ) {
      return selectedItem.label;
      }
      else {
      return null;
      }
      }
      ]]>
      </mx:Script>
      </mx:ComboBox>
        • 1. Re: How to hide itemRenderers in the Grouped rows of an AdvancedDataGrid?
          _Natasha_ Level 4

          You need to change function

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

          to check the type of value.

          If it's a grouped data you need to set this.visible = false and this.visible = true and your code otherwise.

          • 2. Re: How to hide itemRenderers in the Grouped rows of an AdvancedDataGrid?
            savyasachi Level 1

            Thanks for your solution. Looks promising.

             

            How do I verify if the value is Grouped Item or not? Appreciate if you can some pointers - sample code or property name...etc.

             

            Thanks.

            • 3. Re: How to hide itemRenderers in the Grouped rows of an AdvancedDataGrid?
              savyasachi Level 1

              Solved this issue by using mx:rendererProviders element for my AdvancedGrid. Using the depth parameter gives me the ability to hide the itemRenderer for the Grouped rows.


                  <mx:AdvancedDataGrid id="myADG"

                      width="100%" height="100%"

                      initialize="gc.refresh();">       

                      <mx:dataProvider>

                          <mx:GroupingCollection id="gc" source="{dpFlat}">

                              <mx:Grouping>

                                 <mx:GroupingField name="Region"/>

                                 <mx:GroupingField name="Territory">

                                    <mx:summaries>

                                       <mx:SummaryRow summaryObjectFunction="summObjFunc"

                                          summaryPlacement="first">

                                          <mx:fields>

                                             <mx:SummaryField dataField="Actual" summaryFunction="summFunc"/>

                                          </mx:fields>

                                       </mx:SummaryRow>

                                    </mx:summaries>

                                 </mx:GroupingField>

                              </mx:Grouping>

                          </mx:GroupingCollection>

                      </mx:dataProvider>       

                     

                      <mx:columns>

                          <mx:AdvancedDataGridColumn dataField="Region"/>

                          <mx:AdvancedDataGridColumn dataField="Territory_Rep"

                              headerText="Territory Rep"/>

                          <mx:AdvancedDataGridColumn headerText="Actual" dataField="Actual"

                          rendererIsEditor="true"

                          editorDataField="type"/>

                          <mx:AdvancedDataGridColumn dataField="Estimate"/>

                      </mx:columns>

              <mx:rendererProviders>

                  <mx:AdvancedDataGridRendererProvider

                      columnIndex="2"

                      columnSpan="1"

                      depth="3"

                      renderer="TestStatusTypeEditor"/>

              </mx:rendererProviders>

                 </mx:AdvancedDataGrid>