function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Is it possible to create a VF page that overides the "Sort" button?

Hello -


I'm new to VF and currently we add products to our opportunity records for quoting.

The "Sort" button on the Products related list does not sort by what I need and I was

hoping to create a new page to sort my products by a custom field I created.

Any help is appreciated.




This is doable. But the usual way people expect column sorting to work depends upon javascript to avoid a round trip to the server. If that's your goal, I would recommend you not choose this as your first VF project.


If you don't mind the round trip, it's not so hard. You can just requery the records and let soql do the sorting for you.


You'll need to replace the page whose behavior you want to change, and use a pageBlockTable or another of the repeating elements to display the elements of a list of SObjects as rows.


Then you'll need something to click on, with an actionSupport that invokes a controller method that requeries and sorts, and rerenders the pageBlockTable. 


The "Dynamically Updating a Page" chapter in the Cookbook may be helpful.





Even if you could override this button you can't change the sort order.


TehNrdTehNrd could sort it temporarily with in the context of a visualforce page but it won't be saved to the standard opportunity layout.



I have the same sorting issue.
But my requirement here is i have a VF page in which there are list of records.
When a user clicks on a column heder thye total records should be sorted in Ascending or Descending order based on the column.

I have idea about OrderBy clause.
Can you suggest me a solution for this.