You need to sign in to do that
Don't have an account?
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
(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 :-
And here's the VF Page, where all the magic happens :-
You can run this code as is in your test environment.
Make sure to mark it as the answer if it answers your question.
Thanks for the response. I ended up doing something like this, rather than using the StandardSetController.
...and changing the VF to...
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