We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Custom Sorting - Ascending and descending

Hello Syncfustion Team!

I implemented a custom sort comparer for a date column with dd/MM/yyyy format, and is working perfectly for descending order, but how can I implement ascending order?

function sortDateComparer(a, b) {
    a = new Date(a);
    b = new Date(b);
    return a > b ? -1 : a < b ? 1 : 0;
 
}

Thanks in advance.

3 Replies

PS Pavithra Subramaniyam Syncfusion Team October 18, 2019 10:13 AM UTC

Hi Matias, 

Thanks for contacting Syncfusion support. 

We have validated the provided code example and We suggest you to use the below way to achieve your requirement. 

function sortDateComparer(a, b) { 
  a = new Date(a); 
  b = new Date(b); 
  return a > b ? 1 : a < b ? -1 : 0; 
} 
 



Note: If a is less than b return -1 if a greater than b then return 1  
 
Regards, 
Pavithra S. 



MP Matias Puzanowski October 18, 2019 12:43 PM UTC

Thanks a lot for replying and also for providing documentation, but I think that we misunderstood. Sort is working, but only in one way. 

Normal (ordered by IDs):



Descending (ordered perfectly):


Ascending (ordered just as descending):



So how can I do to sort in both ways?

Thanks in advance.








PS Pavithra Subramaniyam Syncfusion Team October 21, 2019 12:20 PM UTC

Hi Matias, 

Thanks for your update. 

We have validated the provided information and checked with our end but we could not face the reported problem, both ascending and descending working fine at our sample. Please refer the below sample for more information. 


[Ascending result] 
 

[Descending] 
 

Could you please share more details or below information that will be more helpful for us to validate further at our end. 

  • Do you want to perform multiple sorting in Grid?
  • Share the full code example and package version details.
  • Share the video demo of your issue
  • If possible share the sample or reproduce the reported problem at our end

Regards, 
Pavithra S. 


Loader.
Live Chat Icon For mobile
Up arrow icon