2 Replies Latest reply on Apr 6, 2007 10:19 AM by craigkaminsky

    labelFunction problems

    craigkaminsky Level 3
      I'm sure there is something really obviously wrong with my labelFunction code but I'm stumped...and not-too-bright vis-a-vis Flex yet! Everything works fine when I do not try and use the labellFunction to format the date in the DattaGrid below.

      AS Code:
      private function formatDate(item:Object):String
      {
      return mmddyyyy.format(item.regDate);
      Alert.show(item.regDate);
      }
      MXML Code:
      <mx:DateFormatter id="mmddyyyy" formatString="MM/DD/YYYY"/>
      <mx:DataGrid id="dgOrgCoupons" dataProvider="{acCouponUsers}" x="10" y="55" width="85%">
      <mx:columns>
      <mx:Array>
      <mx:DataGridColumn headerText="Name" dataField="fullName"/>
      <!-- with the column below, I use dataField="regDate" when not trying to format the date -->
      <mx:DataGridColumn headerText="Registration Date" labelFunction="formatDate"/>
      <mx:DataGridColumn headerText="Event Name" dataField="eventName"/>
      </mx:Array>
      </mx:columns>
      </mx:DataGrid>

      When I add the labeFunction, and this code gets called, it starts to display the users but stops after showing the first fullName entry. Everything else is blank in the grid (and additional entries do not show up). Basically, it halts the processing but throws no error.

      Also, I've added (for testing to try and figure this out) an Alert.show() statement to the formatDate function but it never even gets called. It seems like the labelFunction just isn't getting called when it's in the DataGridColumn tag.

      Thanks for any thoughts or advice!

        • 1. Re: labelFunction problems
          craigkaminsky Level 3
          I've also, after searching the forums, altered my function to include the data grid column:
          private function formatDate(item:Object,col:DataGridColumn):String
          {
          return mmddyyyy.format(item[col.dataField].toString());
          }

          but this doesn't work. Sorry, I meant to note that in my first post.
          • 2. Re: labelFunction problems
            craigkaminsky Level 3
            Okay, please ignore this post. I'm an idiot. I realized the error of my ways:

            correctly working function:
            private function formatDate(item:Object,col:DataGridColumn):String
            {
            return mmddyyyy.format(item[col.dataField]);
            }
            datagridcolumn code:
            <mx:DataGridColumn headerText="Registration Date" labelFunction="formatDate" dataField="regDate"/>

            I had left the dataField off the column, so it was being passed into the function properly.