You need to sign in to do that
Don't have an account?
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
All Answers
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.
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.
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."
The link is directing to a generic VF page. Do you by any chance have an updated link? Would be great to read that.