4 Replies Latest reply on Jun 17, 2009 5:51 PM by Michael Borbor

    format date value in a DataGridColumn?

    richardELeach Level 1

      Hi All-

       

      ... so I made the leap from ColdFusion to Flex, very cool stuff. I'm using FlashBuilder 4 and just completed the "Getting Started With ColdFusion and FlashBuilder 4 beta" which simply shows how to hook a service to a data grid using CFCs. Good stuff. My question: I've modified the code a little and I'm using a date value in my database call, and I need to understand how to format the returned date value from the database to a format of my choosing? I searched around and saw a few different things about date formatting but I think I may have missed the obvious.

       

      What I'm saying is if you're a ColdFusion developer than we simply take the value from the query and use dateFormat(dateValueFromDB, "mm/dd/yyyy") and the formatting happens right there. Is there an equivalent in Flex (sorry, FlashBuilder)? Seems like there might be an extra step since I'm using a DataGridColumn inside of a DataGrid tag, yes?

       

      And while I'm at it, any other former ColdFusion programmers who made the leap to Flex have any resources or suggestions on how to make the transition as least painful?

       

      Thanks in advance,

       

      Rich

        • 1. Re: format date value in a DataGridColumn?
          *Prashant Shelke* Level 4

          You can set labelFunction="myLabelFunction" to dataGridColumn.

           

          public function myLabelFunction(value:Object, column:DataGridColumn):String
          {
              try
              {
                  if(value != null) // value is nothing bt, select Object from dataGrid.
                  {
                      if(value.date != null)
                      {
                          return formatted date from here, using DateFormatter & formatString as U want.
                      }
                      else
                      {
                         return "";
                      }
                  }
              }
              catch(error : Error)
              {
                  Alert.show("error : " + error.getStackTrace());
              }

              return "";   
          }

          • 2. Re: format date value in a DataGridColumn?
            richardELeach Level 1

            Thank you Prashant.

             

            I have to admit, I'm a little surprised (but that's NO surprise, since I'm just learning Flex) that there's no simple tag attribute or something a little less verbose to simply handle the formatting of a date value in the DataGridColumn; this seems like a lot of effort to achieve just a little formatting, especially since the Flex framework has gone through the effort to make generating an extremely functional data grid so easy. But if that's how it is, so be it.

             

            Thank you again!

             

            Rich

            • 3. Re: format date value in a DataGridColumn?
              *Prashant Shelke* Level 4

              I think you can make use of such function as Util function means to reuse & its always better to set it at column level instead of iterating dataProvider.

              • 4. Re: format date value in a DataGridColumn?
                Michael Borbor Level 4

                You could've used an itemRenderer. It'll be a cleaner solution.