We have a visualforce page which has a pageblock table with 3 columns in it. We would like to give user the ability to sort ascending and descending based on the last modified date.

i.e When user clicks on this column, it should be able to sort both ways.

Currently We have sorted the query returning data using order by Last Modified Date in the controller. This displays data by default but still users would like to have the ability.

What is the best way to get this achieved ? Any suggestions or code sample will be helpful. Appreciate it.

Thanks NS Mani

closed as off-topic by Sebastian Kessel, Reshma, David Reed, crmprogdev, glls Feb 10 at 15:29

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – Sebastian Kessel, Reshma, David Reed, crmprogdev, glls
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    You can do server-side as Murali mentions or you can do client-side using e.g. datatables.net but you need decent JavaScript skills to do it that way. – Keith C Feb 10 at 11:17
  • 1
    See also this question and its answers for potential solutions. – sfdcfox Feb 10 at 13:02

You will need dynamic SOQL for a server side solution to achieve this. Answered here by Jeff Bennett: Sorting column in Data table

  • This should be written as comment. – Santanu Boral Feb 10 at 7:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.