4 Replies Latest reply on Oct 12, 2009 11:57 AM by Handycam

    Using labelfunction to replace a label in grouped ADG

    Handycam Level 1

      I have an advanced datagrid with a grouping collection.

       

      The grouped label is a series of short phrases, to make the XML easier to read: 1h, 2h, 3h, etc.

       

      In the actual grid, though, I'd rather replace these with more user-friendly phrases: "One Hour", "Two Hours", "Three Hours", etc.

       

      what's the easiest and cleanest way to do this?

        • 1. Re: Using labelfunction to replace a label in grouped ADG
          Sameer Bhatt Adobe Employee

          Use AdvancedDataGrid.groupLabelFunction

           

          -Sameer

          • 2. Re: Using labelfunction to replace a label in grouped ADG
            Handycam Level 1

            Thanks.  Can you provide an example of how to use this to replace content?

             

            For example, if the current label is "1h" I want to replace that with "One

            Hour Before".

            • 3. Re: Using labelfunction to replace a label in grouped ADG
              Sameer Bhatt Adobe Employee

              Have a look at this code snippet -

               

                   <fx:Script>

                        <![CDATA[

                             import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;

                              

                             private function grpLabelFunc(item:Object, col:AdvancedDataGridColumn):String

                             {

                                  // this field can be changed by setting the Grouping.label property

                                  var dataField:String = "GroupLabel";

                                   

                                  switch (item[dataField])

                                  {

                                       case "1h": return "One Hour Before";

                                       case "2h": return "Two Hour Before";

                                       case "3h": return "Three Hour Before";

                                       case "4h": return "Four Hour Before";

                                  }

                                  return item[dataField];

                             }

                        ]]>

                   </fx:Script>

                   <fx:Declarations>

                        <fx:Array id="arr">

                             <fx:Object name="1h" />

                             <fx:Object name="2h" />

                             <fx:Object name="3h" />

                             <fx:Object name="4h" />

                        </fx:Array>

                   </fx:Declarations>

                   <mx:AdvancedDataGrid id="adg" groupLabelFunction="grpLabelFunc" creationComplete="gc.refresh()">

                        <mx:dataProvider>

                             <mx:GroupingCollection id="gc" source="">

                                  <mx:Grouping>

                                       <mx:GroupingField name="name" />

                                  </mx:Grouping>

                             </mx:GroupingCollection>

                        </mx:dataProvider>

                        <mx:columns>

                             <mx:AdvancedDataGridColumn dataField="name" />

                        </mx:columns>

                   </mx:AdvancedDataGrid>

               

              -Sameer