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
JWSJWS 

StandardSetController and grouping pageBlockTables

We have several divisions of our company, and I am trying to create a VF page using an extension that will return a list of our custom object records (Roles__c), but then somehow group them on a page by division using maybe pageBlockTables.  I'm created this VF page to use as a Site so that another area of our company can view some of our data.

No editiing of this data will need to be done -- it's display/read only.

 

Here is my basic VF at the moment:

 

<apex:page standardController="Role__c" showheader="false" recordSetVar="roleController" tabstyle="Role__c" extensions="roleControllerExtension" >

<apex:sectionHeader title="Bill Account" subtitle="Customer On-Call Contacts"/>

<apex:pageBlock title="Division A">
    <apex:pageBlockTable value="{!roles}" var="r">
      <apex:column value="{!r.Customer_Name__c}"/>
      <apex:column value="{!r.Bill_Account__c}"/>
      <apex:column value="{!r.Contact_Name__c}"/>
      <apex:column value="{!r.Title__c}"/>
      <apex:column value="{!r.Phone__c}"/>      
      <apex:column value="{!r.Mobile__c}"/>      
    </apex:pageBlockTable>
  </apex:pageBlock>

</apex:page>

 


I currently have this class thrown together:

 

public class roleControllerExtension {
private final Role__c r;

    public roleControllerExtension (ApexPages.StandardSetController stdController){}
     
    public String queryString(){
        String queryString = 'SELECT r.Id, r.Name, Customer_Name__c, Bill_Account__c, Contact_Name__c,Title__c,Phone__c,Mobile__c, Division_Name__c FROM Role__c r';
        return queryString;
    }

     public ApexPages.StandardSetController roleController     {
         get {
            if(roleController == null) {
                String query = queryString();
                return new ApexPages.StandardSetController(Database.getQueryLocator(query));
         }
            return roleController;
         }
     }

    public List<Role__c> getRoles(){
        return (List<Role__c>) roleController.getRecords();
    }
}

 

What I'd like is for each pageBlockTable to contain one division's roles.  Does anyone have a recommendation of how to get there? The recordSetVar is going to bring back ALL division roles, which is fine, but how do I get them in separate pageBlockTables?

Thanks in advance for your time.
Jamie

 

Saurabh DhobleSaurabh Dhoble

(A) You break down your rows into multiple Lists, say Division_1_List, Division_2_List

(B) Create a master list that will hold these lists :- List<List<Role__c>> MasterList

(C) Put all these lists into a master list (masterList.Add(Division_1_List))

(D) Put your pageblocktable inside a repeat, and assign the datasource for each division. I can't explain this, so here's something I quickly wrote to demonstrate this :-

 

Class :-

 

public class Split_Division_Test {
    List<String> dataList_division_1;
    List<String> dataList_division_2;
    List<List<String>> MasterList;
    
    public Split_Division_Test()
    {
        dataList_division_1 = new List<String>();
        dataList_division_2 = new List<String>();
        MasterList = new List<List<String>>();
        dataList_division_1.add('Div_1_1');
        dataList_division_1.add('Div_1_2');
        dataList_division_1.add('Div_1_3');
        
        dataList_division_2.add('Div_2_1');
        dataList_division_2.add('Div_2_2');
        
        MasterList.add(dataList_division_1);
        MasterList.add(dataList_division_2);
    }
    
    public List<String> Div_1_Data
    {
        get
        {
            return dataList_division_1;
        }
    }
    
    public List<String> Div_2_data
    {
    	get
        {
            return dataList_division_2;
        }
    }
    
    public List<List<String>> Master_Data
    {
        get
        {
            return MasterList;
        }
    }
}

 

And here's the VF Page, where all the magic happens :-

 

<apex:page controller="Split_Division_Test">
    <apex:form>
        <apex:pageBlock>
        	<apex:repeat id="myRepeat" value="{!Master_Data}" var="p">
            	<apex:dataTable id="myInnerDataTable" value="{!p}" var="innerStr">
                	<apex:column headerValue="MyCustomHeader" value="{!innerStr}"/>
                </apex:dataTable>
                <br />
                <p>------------------------------</p>
            </apex:repeat>
        </apex:pageBlock>
    </apex:form>    
</apex:page>

 

You can run this code as is in your test environment.

Make sure to mark it as the answer if it answers your question.

JWSJWS

Thanks for the response.  I ended up doing something like this, rather than using the StandardSetController.

public class roleWrapperController {
    public List<baRole> roleList {get;set;}
    public List<OPCO_Division__c> divList {get;set;}

    public List<baRole> getRoles(){
        if(roleList == null){
            roleList = new List<baRole>();
            for (Role__c r: [SELECT Division__c, Name, Customer_Name__c, Bill_Account__c, Contact_Name__c,Title__c,Phone__c,Mobile__c FROM Role__c WHERE Role__c.Role__c='On-Call Contact']){
                roleList.add(new baRole(r));        
            }
        }
        return roleList;
    }
    public class baRole{
        public Role__c role {get;set;}
        public baRole(Role__c ro){
            role = ro;
        }
    }
    public List<OPCO_Division__c> getDivisions(){
        divList = new List<OPCO_Division__c>();
        for (OPCO_Division__c div : [SELECT Name from OPCO_Division__c ORDER BY External_Division_ID__c]){
            divList.add(div);
        }
        return divList;          
    }
}

...and changing the VF to...

<apex:page controller="roleWrapperController" showheader="false" tabstyle="Role__c">

<apex:sectionHeader title="Bill Account" subtitle="Customer On-Call Contacts"/>

<apex:repeat value="{!divisions}" var="d">
<apex:pageBlock title="{!d.Name}">
<apex:pageBlockTable value="{!roles}" var="r" >
      <apex:column headerValue="Division" value="{!r.role.Division__c}" />      
      <apex:column value="{!r.role.Customer_Name__c}" />
      <apex:column value="{!r.role.Bill_Account__c}" />
      <apex:column value="{!r.role.Contact_Name__c}" />
      <apex:column value="{!r.role.Title__c}" />
      <apex:column value="{!r.role.Phone__c}" />      
      <apex:column value="{!r.role.Mobile__c}"/>      
</apex:pageBlockTable>

</apex:pageBlock>
</apex:repeat>
</apex:page>
                  

 
So, I'm going through the Division__c object, returning the names, then sending those back as a list I can iterate through along with the Role__c stuff.  The problem now is that using this method, ALL of the Roles repeat for every division.  I was going to do some kind of "rendered=" and check to see if the division name I'm iterating through matched the name on the Role record.  If it did, render that pageBlockTable.

However, you apparently can't refer to the values/var list in the "render" attribute of pageBlockTable -- I'm assuming that the list doesn't really "exist" yet or something.  

Any other ideas for using this code and ensuring that only the divisions with roles are rendered?  I think I'm close...
Jamie