+ Start a Discussion

Storing sorting direction of Comparable interface


I have a VisualForce page which has a custom controller, I am displaying some data on a PageBlockTable and I have implemented the Comparable interface on a wrapper class and the sorting works fine.

I am now trying to allow you to sort in ascending or descending direction, but to do this I was planning on storing the direction inside a variable on the custom controller inside the top level class.

But the variable is lost each time the user goes to sort, I assume because the viewstate is lost.

I tried storing the variables inside another class and creating an instance of that class but the same thing happens because the instance is probably lost.

What would the correct way of doing this be? I could probably do this in javascript and pass ASC or DESC but I prefer the other method as I also want to extend this to other columns.

Thank you