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
Richa KRicha K 

Splitting one column into multiple

Hi everyone,


I have a normal pageblock table in my page. It shows data in a single column. I also do have checkbox bound to them.


For eg : original OP :




[] F

And desired one is :


[]A    []B      [] C
[]E   []F





Thanx and eagards,

Shailesh Patil


There's probably a few ways to do this, the way I'd approach it is to put the items into a wrapper class that contains up to three instances of your object. 


e.g. controller


public MyController
   public List<MyWrapper> myWrappers{get; set;}

   public class MyWrapper
      public Account myAcc1 {get; set;}
      public Account myAcc2 {get; set;}
      public Account myAcc3 {get; set;}

      public Boolean checkbox1 {get; set;}
      public Boolean checkbox2 {get; set;}
      public Boolean checkbox3 {get; set;}

   public MyController()
      myWrappers=new List<MyWrapper>();
      Integer idx=0;
      MyWrapper wrap;
      for (Account acc: [select id, Name from Account limit 12])
         if (0==Math.mod(idx, 3))
            wrap=new MyWrapper();
         if (1==Math.mod(idx, 3)
         else if (2==Math.mod(idx, 3)


<apex:pageBlockTable value="{!MyWrappers}" var="wrap">
   <apex:column headerValue="Col 1">
      <apex:outputField value="{!wrap.myacc1.Name}"/>
      <apex:inputCheckBox value="{!wrap.checkbox1}"/>
   <apex:column headerValue="Col 2">
      <apex:outputField value="{!wrap.myacc2.Name}"/>
      <apex:inputCheckBox value="{!wrap.checkbox2}"/>
   <apex:column headerValue="Col 1">
      <apex:outputField value="{!wrap.myacc3.Name}"/>
      <apex:inputCheckBox value="{!wrap.checkbox3}"/>


Not compiled, but hopefully you get the drift.


Can you show me another way?


I reckon this could be achieved with dynamic visualforce bindings, storing the information in maps containing lists.  It would end up being a much more complex solution to maintain though.  Wrapper classes is always my preferred solution.


I think you need to increment idx....right?





Correct.  First typo of many no doubt!


Hi Bob

Could you please share the total code to split the one column into 3 columns (As mentioned above)?



I don't have any code that does it via dynamic bindings I'm afraid.  As I mentioned above, I always use wrapper classes unless I have no option, as it makes it easier for those that come after me to maintain.

Richa KRicha K

Hi Bob,

Thanx a lot. That worked !


Now can you guide me on another issue?

How can I pass the checkbox values and update the corresponding variable in the class? Note that one can select multiple checkboxes.


You don't need to do anything further to update the value in the class, as the checkbox is part of the viewstate.


I wrote a blog post on this a while ago - that should give you the details: