Visualforce Table with Alphabet Filter and Sortable Columns

16 Feb

This Visualforce page contains apex:pageBlockTable to demonstrate a few different concepts.

  • Sortable Columns in an apex:pageBlockTable
  • Alphabet Filter that filters on the current sorted column
  • Use of the ApexPage StandardSetController
  • Selecting an individual record in the table using a link
  • Selecting multiple records with a column of checkboxes using a Sub Class(Wrapper Class) to hold the boolean value.

Both single and multiple record selection were included for demonstration. Most actual projects would only require one type, and I thought it would be easy to cut whatever was not needed. The search for the Billing Address fields was consolidated into one field to make the interface simpler. Below is an example of what the Visualforce table looks like with the alphabet filter, sorted columns, address search, and checkbox record selection.

Sortable apex:pageBlockTable, alphabet filter, checkbox selection and link selection

Before jumping into the code, I wish I could reference and say thanks to the source that I used as a starting point for the alphabet filter. I’ve found similar code, but not the original. I’m grateful for the help others have provided and will update this if I find it.

7 Replies to “Visualforce Table with Alphabet Filter and Sortable Columns

  1. Hi Dave…thanks so much, this is very helpful! I need to be able to build this as an editable grid with the sorting and filtering with one Save button to update all records. I have edited the code from outputField to inputField and the sort and filter works great. Now I just need a way to save all the updates. What would be the method to build for this? TIA!

    • You would need a save method that performed an update on Accounts that had changed in the AccountList. You could try creating a map of accounts in the getCurrentAccountList method before it displayes on the page, so you know which records were edited. The account put into the map would need to be cloned, so it didn’t share the same memory. Then in the save you could compare the AccountList to the map, and update only the records that had changed.

  2. I read a lot of interesting posts here. Probably you spend a lot of
    time writing, i know how to save you a lot of time, there is an online tool that
    creates readable, google friendly posts in minutes, just
    type in google – laranitas free content source

  3. Thank you for sharing this code! It was exactly what I needed for a client implementation! I hope that someday I am a good enough programmer to share such great content.

  4. This post is really helpful , and more over sorting here used controller , unlike many blogs,,which suggested to use JQuery,
    This saved a worthy time.
    Thanks and all the best ,,,

Comments are closed.