You need to sign in to do that
Don't have an account?
singhd62
Custom Sorting on Multiple fields
Hi,
Want to perform custom sorting on multiple fields in apex same as Excel which narrows down the list lets say from 100 to 5 using sort type (asc or desc)
Thanks,
singhd62
Want to perform custom sorting on multiple fields in apex same as Excel which narrows down the list lets say from 100 to 5 using sort type (asc or desc)
Thanks,
singhd62
If my understanding is incorrect, please provide more details.
eg:
acc1 10 Status1 900
acc2 20 Status2 907
acc3 80 Status3 902
acc4 10 Status1 800
acc5 20 Status5 904
acc6 40 Status6 905
acc7 40 Status7 906
acc8 30 Status8 901
acc9 25 Status9 908
acc10 33 Status10 909
below will be the sorted list:
acc4 10 Status1 800
acc1 10 Status1 900
acc2 20 Status2 907
acc5 20 Status5 904
acc9 25 Status9 908
acc8 30 Status8 901
acc10 33 Status10 909
acc6 40 Status6 905
acc7 40 Status7 906
acc3 80 Status3 902
Hi,
You can try out datatable multi ordering on columns plugin in your vf page.
For more infor please go through http://www.datatables.net/examples/basic_init/multi_col_sort.html (http://www.datatables.net/examples/basic_init/multi_col_sort.html)
Thanks,
N.J
Review the article at the below link for more examples
http://developer.force.com/cookbook/recipe/sorting-query-results
And then we iterate over it by applying sorting in the for loop as there is a field which gets updated during the execution. And again at the start of the loop we need to sort on that runtime value.
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_comparable.htm
I mean to say the first sorted list need to be retained while applying 2nd field sorting..
You'll be able to do it like this (a and b are the comparable values):
if (a > b) {
compare = 1;
} else if (a < b) {
compare = -1;
} else {
if (c > d) {
compare = -1;
} else if (c < d) {
compare = 1;
}
}