Search code examples
checkboxpaginationapex-codevisualforce

Visualforce Pagination with StandardSetController - how to persist Checked values across pages


I've used standardSetController to implement pagination and wrapper to process selected records.

Everything works fine until I try to retain check-box statuses across different pages of records. Suppose, few records are checked on page #1 and clicked on next button. The clicked previous button to come back to the page #1. Records which were checked previously get unchecked.

Could anyone let me know how to persist checked values across pages.

Thanks in advance.


Solution

  • I've resolved this the following way:

    • create a Set<Id> selectedRecordIds
    • On each nextPage, prevPage, lastPage, etc and each action you do on the set, first update the set of selectedIds with the current page's isSelected values (don't forget to remove the non-selected items if they are in the Set of Id's)
    • When loading a new page of records, in the get method loop through them and set (or unset) their isSelected value based on whether or not they are present in the selectedRecordIds set.