function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TehNrdTehNrd 

How To: Sort Tables

One of the more common requests I've seen on these boards is the ability to sort dataTables. The options usually consist of:

 

1) Requery the data by changing the order by part of the SOQL statement

2) Use a javascript library

3) Build your own sorting logic with Apex.

 

Wouldn't it be great if the sort() method for Lists could sort collections of sObjects instead of only primative data types? Of course! So I set out to create exactly this. A truly dynamic sort method that can take a List of nearly any object, custom or standard, and sort by the field you determine. I was able to successfully build this and now it is very easy to sort dataTables (or pageBlockTables). 

 

Check it out here: http://wiki.developerforce.com/index.php/Sorting_Tables

 

http://wiki.developerforce.com/index.php/Sorting_Tables

-Jason

Message Edited by TehNrd on 04-13-2009 10:57 AM
Best Answer chosen by Admin (Salesforce Developers) 
icogicog
Thanks a lot ! This helps a lot of developers like me, until salesforce provides this functionality, it at all.

All Answers

icogicog
Thanks a lot ! This helps a lot of developers like me, until salesforce provides this functionality, it at all.
This was selected as the best answer
vacalocavacaloca

Thanks! 

 

Is there any potential to pass in a wrapperclass as opposed to an SObject?  Something Like: 'superSort.sortList(allPCP,sortField,order);' ??

 

where 'allPCP' is a wrapper referenced in a datatable.

craigmhcraigmh

Is there any chance of getting this to work with a List that contains AggregateResult items?

 

EDIT:

I do have code to do this, but not efficiently. Since I'm using a read-only Visualforce page, and have up to 10k items in a collection, sorting these is not feasible as I run into the script statement limit.

craigmhcraigmh

I got it to work fairly well by removing the whole "If" conditional for the reference field and changing every variable of type "sObject" to type "AggregateResult."

AlanLamAlanLam
Hi TehNrd,
The link is directing to a generic VF page. Do you by any chance have an updated link? Would be great to read that.