0

I am sorting an Opportunity with its Name, Amount, Stage, Owner(All are in a data table as Columns). Now I want to sort (Ascending or Descending) the results on the client side when I click on the column. I have gone through the following link and is helpful. Lightning client side sorting

Is there any other efficient sorting approach to handle this? (like Merge Sort/Quick Sort).As this contains large data sets the performance will go down if we use the same approach provided in the link. Can anyone please give me a working approach to sort large data sets in this context

  • no you have to do go with the same approach using shared by sfdcfox – Ratan Paul Jul 5 '17 at 7:05
  • @RatanPaul Is there any specific reason to go with the same approach? Suppose If the page has 1000 opportunities how many times it needs to compare each value with other value? Also one more question I have is If I want to sort the Start and End Dates of Opportunity will this sorting logic work for that? Suppose the Owner Names are in this way "ABC - Salesforce - USD", "WW-SF-CAN". Will this be sorted if I click on the Owner Name column? Just want to know if any other logic is required to handle these cases – sri Jul 5 '17 at 7:21
  • Maybe I'm not understanding the question, but why can't you just let DataTables do the sorting itself? I use DataTables in my Lightning Components, and sometimes have tables with 1000's of entries (such as if I list all Contacts in Salesforce) and I've never seen a performance issue when sorting on any columns. EDIT: I just displayed a DataTables with over 4000 Contact records, and see no performance impact when clicking column headers to sort on Name, Account, etc. – Florissant53 Jul 5 '17 at 21:30
1

I think this would be best approach to do so in javascript which is totally client side and it wont take much time as I am already using it on large data set it is not taking time. Again if you think it s taking time then please use lightning:spinner as well. I f you notice on standard list view on objects they are totally on server side.

| improve this answer | |
  • I just want to know why this is the best approach for sorting in javascript on client side? If it contains >500 records it will compare so many times. Also I want to know if this logic works for Sorting start date/end date, Owner Names like " ABC - Salesforce -USD", "WW-SF-CAN"? – sri Jul 5 '17 at 7:34
  • As if you see in salesforce when we sort wrapper list we need to use comparable interface in the class to sort wrapper list which is the same as we have here in javascript also for date you need to make some small tweeks in code and you will be ready and for Names like " ABC - Salesforce -USD", "WW-SF-CAN" you can user trim() to remove extra space that we have in starting or end of characters. I am also using the same on large data set like 25000 of records and it just take around 1 second to sort which I cover by Lightning spinner. – Rishi Golyan Jul 5 '17 at 7:43
  • Thanks for the information. For dates should we use the difference between a&b? Can you let me know how exactly I need to tweek for sorting the Names? – sri Jul 5 '17 at 7:56
  • How to use lightning spinner while sorting the lightning data table records on client side – Harshit Verma bluCursor May 7 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.