5 Replies Latest reply on Sep 19, 2008 1:02 AM by nikos101

    Dates are ordered by date in my Flex arrayCollection

    nikos101 Level 2
      I have passed a sql database result from coldfusion into FLex. One column of the result contains a string of this format:

      mm/dd/yyyy

      09/08/2008

      How can I process this result so that the dates are ordered by date in my Flex arrayCollection?

      Thanks for anu help :)
        • 1. Re: Dates are ordered by date in my Flex arrayCollection
          Ventis85 Level 1
          In this case, I would say sort it in your query. Much easier.
          • 2. Re: Dates are ordered by date in my Flex arrayCollection
            nikos101 Level 2
            Thanks but this must be done on the client.
            • 3. Dates are ordered by date in my Flex arrayCollection
              EvolvedDSM Level 2
              Use a sort on your ArracyCollection.

              Import the Sort classes & AC class:
              import mx.collections.Sort;
              import mx.collections.SortField;
              import mx.collections.ArrayCollection;

              First, declare a sort and sortField variable, along with an ArrayCollection:
              private var sortColumn:Sort;
              private var sortByDate:SortField;
              [Bindable]
              private var myAC:ArrayCollection;

              Next, in a function, code your AC & Sort:
              myAC = new ArrayCollection;
              sortColumn = new Sort();
              sortByDate = new SortField("dateToday", true, false, true);
              // 'dateToday' is the name of your Date column in the ArrayCollection, change appropriately
              sortColumns.fields=[sortByDate];
              myAC.sort = sortColumn;
              myAC.refresh();

              Let me know if this works :)

              EDIT: made a typo in my script, it's changed now
              • 4. Re: Dates are ordered by date in my Flex arrayCollection
                Level 7

                "nikos101" <webforumsuser@macromedia.com> wrote in message
                news:gatcif$m10$1@forums.macromedia.com...
                >I have passed a sql database result from coldfusion into FLex. One column
                >of
                > the result contains a string of this format:
                >
                > mm/dd/yyyy
                >
                > 09/08/2008
                >
                > How can I process this result so that the dates are ordered by date in my
                > Flex
                > arrayCollection?
                >
                > Thanks for anu help :)
                >

                You can either use the split function on the string to break the date at the
                "/" marks, or you can "fill out" the date and use the parse() function of
                the date object.

                HTH;

                Amy


                • 5. Re: Dates are ordered by date in my Flex arrayCollection
                  nikos101 Level 2
                  This seems to sort them:

                  public function sortByDateModified( sourceArray: ArrayCollection ): ArrayCollection
                  {
                  if( sourceArray == null || sourceArray.length == 0 )
                  return new ArrayCollection();
                  var sort: Sort = new Sort();
                  var sortField: SortField = new SortField( "dateAdded" );
                  sortField.descending = false;
                  sort.fields = new Array( sortField );
                  sourceArray.sort = sort;
                  sourceArray.refresh();
                  return sourceArray;
                  }