1 Reply Latest reply on Jul 22, 2015 4:28 AM by chopravab

    Date sorting in datagrid always returns different results for "rows with same dates"

    chopravab

      Say I have a Datagrid like below and I have sorted on a column which is a date:

      (See screenshot below the highlighted rows have same date and 419059 is above 419058)

       

      IMG1.png

      Once I click on the row, the row is shifted,see below:

      (419059 is now below 419058)

      Img2.png

      Issue: The position of the row should not change as the same date sorting function is called.This looks very odd when there are multiple rows with same date as row keep jumping when selected.

      Note:This only happens when I sort them by clicking on State_change_time.and on click date sorting happens.

       

      Code Snippet:

      <datagridextensions:ExtendedDataGridColumn dataField="UNIT_STATE_START_TIME"

                           textAlign="right"

                           labelFunction="getDateLabel"

                           headerText="{ResourceManager.getInstance().getString('EntityColumns', 'UNIT_STATE_START_TIME')}"

                           visible="false" width="100"

                           sortCompareFunction="{Sorter.createInstance('UNIT_STATE_START_TIME').dateCompareFunction}"/>


      public function get dateCompareFunction(): Function {

                           return dateCompare;

                    }


      private function dateCompare(item1: Object, item2: Object): int {                                     

                           var d1: Date = Utils.createDate(item1[_attribute]);                 

                           var d2: Date = Utils.createDate(item2[_attribute]);          

                           if (!d1 && !d2) return 0;

                           if (!d1) return -1;

                           if (!d2) return 1;

                           return d1 < d2 ? -1 : d1 > d2 ? 1 : 0;                

                      }

       

      Any help is much appreciated.