I have a pageblocktable with a bunch of products and i just want to shuffle each product in list,

Can anyone please suggest me the way how to implement this functionality in visualforce page and save it to the salesforce database ?


thanks a lot in advance !![enter image description here

  • what do you mean when you say you want to shuffle?
    – Raul
    Mar 17, 2017 at 14:31
  • It will be good if you can explain with examples and try to put code whatever you have tried so far Mar 17, 2017 at 14:32
  • @SantanuBoral i did not write any code yet, i just need suggestion from you guys How to do shuffling in pageblocktable (let me update my post and give you screenshot prepared by me) Mar 17, 2017 at 14:38
  • You could leverage jQuery, refer this: safnet.com/writing/tech/2012/07/… Mar 17, 2017 at 15:01
  • Here is one more: stackoverflow.com/questions/16524497/… Mar 17, 2017 at 15:03

2 Answers 2


The pageBlockTable component accepts a list of records to be rendered on the page, so I'd say that whatever you want to do to order those records you will need to act on the list.

In your controller you will have a list variable, and if you want to sort or shuffle it then you have to shuffle/sort this list of records.

Since you don't want any help with the code, then I suppose you already know how to do this.

  • thanks Renato, that means yes the given shuffle in image is possible,,, right ? Mar 17, 2017 at 14:55
  • Yes. It is possible. Mar 18, 2017 at 0:23

You have to manipulate the list on the backend and re-render:

You'd basically need to create a true List data-structure.

Create a node class that stores the value as well as a reference to the preceding node and following node.

Create a List class that contains a reference to the first node in the list.

This list class should have a method that will follow the node chain and generate a SF compatible list that will be displayed on the page.

This list class should have a method that will crawl down the chain looking for the specified node, once found, it will determine direction (up or down) and grab the node that is relative to the selected on in that direction. The method should than flip the references around.

For instance, if you want to move an item down the list, grab the desired node grab the following node, set the desired node as the following node to the now preceding node, set the preceding node of the now preceding node to the preceding node of the now following node, set the preceding node of the now following node to the following node of the now preceding node

now, rerender.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .