I am attempting to sort a list based on user clicking columns on visualforce page. Seems like the comparable interface is the best way to do this.
I can sort using static variables but it's messy. I would like to have dynamic variable to compare the list elements; however, I am receiving an error -- "Method does not exist or incorrect signature." Any help is greatly appreciated.
This works but I will need many more if else conditions, one for each column. Plus a check to see what column the user clicked.
if(Load.origincity > Loadtocomp.load.origincity)
return SortOrder.equals('asc') ? 1 : 0;
else
return sortOrder.equals('asc') ? 0 : 1;
This way is much cleaner but it's not working.
if((string)Load.get(comparefield) > (string)Loadtocomp.load.get(comparefield))
return SortOrder.equals('asc') ? 1 : 0;
else
return sortOrder.equals('asc') ? 0 : 1;
This is full comparable interface class (with error)::::
public class loadsort implements Comparable
{
public parseUtility.load load {get; set;}
public loadsort(parseutility.load ld)
{
load = ld;
}
public Integer compareTo(Object vLoad)
{
loadsort LoadToComp = (loadsort )vLoad;
if((string)Load.get(comparefield) > (string)Loadtocomp.load.get(comparefield))
return SortOrder.equals('asc') ? 1 : 0;
else
return sortOrder.equals('asc') ? 0 : 1;
}
}
This is the error:::::: Method does not exist or incorrect signature: [ParseUtility.load].get(String)