3 Replies Latest reply on Jul 24, 2006 5:27 PM by ntsiii

    Formatting DataGrid Data

    ANSCORP
      Is there an easy way to format the data contained within a DataGrid cell? I'm looking for a function similar to the "mask" attribute of the cfgridcolumn tag in the cfform paradigm. I need to display a cell's date value in the format "mm/dd/yyyy" and I can't seem to find a way to do this. I've researched the docs online and help topics and they seem to point to an "itemRenderer" function, but the documentation doesn't have many examples. Since I'm a complete moron, I'd need to see an actual example of how to format the date as I need it withing the DataGrid.

      Many Thanks,
      M. McConnell
        • 1. Re: Formatting DataGrid Data
          ANSCORP Level 1
          I may have stumbled on to a way to do this inline. Here is the code excerpt for my DataGridColumn:
          <mx:DataGridColumn dataField="posted" headerText="Posted" width="50">
          <mx:itemRenderer>
          <mx:Component>
          <mx:Text text="{(data.posted.getMonth()+1)+'/'+(data.posted.getDate())+'/'+data.posted.getFullYear ()}"/>
          </mx:Component>
          </mx:itemRenderer>
          </mx:DataGridColumn>

          Is there a better way? This may not be the most efficient means available.

          Thanks Again,
          M. McConnell
          • 2. Re: Formatting DataGrid Data
            TucsonJava Level 1
            You could also use the LabelFunction property on the DataGridColumn. Then in the LabelFunction itself, use a DateFormatter to format the data the way you want. Although, it looks like what you have would work just fine.
            • 3. Re: Formatting DataGrid Data
              ntsiii Level 3
              If you have performance issues, try the labelFunction suggestion. I have "heard" some folks complain about itemRenderers bing a bit slow. I have no direct experience.

              Tracy