0 Replies Latest reply on Dec 28, 2010 1:25 AM by screen22876

    Sorting date fields with null values

    screen22876

      Hi,

       

      I have a date column in a advanced datagrid. I want to sort the dates with ascending or descending order. But this date column can also contain some null values. But my requirement is to display all blank dates in the end of the datagrid rows always. I am using sortCompareFunction here and the code as follows.

       

      private function date_sortCompareFunc(itemA:Object, itemB:Object):int {
                   var dateA:Date = new Date(Date.parse(itemA.dob));
                  var dateB:Date = new Date(Date.parse(itemB.dob));
                  if (itemA.dob == "" || itemA.dob == null) return -1;
                  else if (itemB.dob == "" || itemB.dob == null) return 1;
                  else return ObjectUtil.dateCompare(dateA, dateB);
              }

       

      Actual result: In case of ascending blanks dates are displayed in the top. In case of descending blank dates are displayed in the end.

      Expected result: Blank dates should displayed in the end in both the cases.

       

      Please let me know if I doing anything wrong here.

       

      Regards,

      Susant