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
Lukas Razim 29Lukas Razim 29 

Grid with fixed number of rows and columns per page

Hi everyone,

Im trying to generate table of all campaign members with their names and addresses, render as pdf (or html or whatever) but with fixed number of rows and columns per page. The idea is that I need this table to be printed on paper with stickers that could be used on envelopes and sent to those members.
I added custom button on Campaign layout generating the pdf, but Im struggling with the code (Im really no coder btw:). See below code, what I just started but got stuck, this only generates cells in one row... I just used Account and Email fields instead of address otherwise it is same. Could please somebody tell me how to modify to make grid 3x10 fixed? Many thanks

<apex:page standardController="Campaign" showHeader="false" renderAs="pdf" applyBodyTag="false">
  <span style="font-family: Arial Unicode MS">
     <table border="0" width="100%" id="table4">
           <apex:repeat value="{!Campaign.CampaignMembers}" var="line">         
           <td>{!line.Contact.Name}<br/>{!line.Contact.Account}<br/>{!line.Contact.Email}<br/></td>            
        </apex:repeat> 
    </table> 
  </span>  
</apex:page>
David ZhuDavid Zhu
You may use apex:pageblocktable component.
<apex:pageblockTable value="{!Campaign.CampaignMembers}" var="item" rows="10">
                        
   <apex:column value="{!item.ContactName}" headerValue="Name"  /> 
   <apex:column value="{!item.Contact.Account}" headerValue="Account"  /> 
   <apex:column value="{!item.Contact.Email}" headerValue="Email"  /> 

......

 
Lukas Razim 29Lukas Razim 29
Hi,

Thank you David but I need all the information (Name, Account, Email) in one cell of the grid and the grid to be 3x10. This way Im getting something like this below as result.

User-added image
David ZhuDavid Zhu
Actually, the code snippet will generate the same table in your screen shot.Specifically, it is a grid of 10 rows and 3 columns.
Not sure what you mean 'all the information (Name, Account, Email) in one cell'
 
Lukas Razim 29Lukas Razim 29
I meant name, account and email of one contact 1 in one cell, Then same for second contact in second cell and so on. Just imagine those are stickers with your name and address that will be stick on envelopes. I just dont have fields for Address so Im using Account and Email fields, but the logic is same. Maybe the schema below will help? thank you

Contact1 Name          Contact2 Name         Contact3 Name         
Contact1 Account      Contact2 Account      Contact3 Account      
Contact1 Email          Contact2 Email          Contact3 Email

Contact4 Name          Contact5 Name         Contact6 Name         
Contact4 Account      Contact5 Account      Contact6 Account      
Contact4 Email          Contact5 Email          Contact6 Email           
David ZhuDavid Zhu
You may create a controller extension for Campaign object and add add a inner class.

 
public class CampaignExtController
{
    public list<member> Members {get;set;}

    public AccountSalesController(ApexPages.StandardController ctrl)
        {
        //populate member information into Members        
    }

    public class member
    {
        string contact1;
        string account1;
        string email1;
        string contact2;
        string account2;
        string email2;
        string contact3;
        string account3;
        string email3;
    }

}


in VF Page, add extention to the page and use the following snipet. 


 
<!-- use apex:datatable or apex:pageblocktable  or apex:repeat-->

                <apex:datatable value="{!Members}" var="item" columns="3" rows="10">

                <apex:column >
                    <hr/><apex:outputtext value="{!item.contact1}"/>
                    <hr/><apex:outputtext value="{!item.account1}"/>
                    <hr/><apex:outputtext value="{!item.email1}"/>
                </apex:column>
                <apex:column >
                    <hr/><apex:outputtext value="{!item.contact2}"/>
                    <hr/><apex:outputtext value="{!item.account2}"/>
                    <hr/><apex:outputtext value="{!item.email2}"/>
                </apex:column>
                <apex:column >
                    <hr/><apex:outputtext value="{!item.contact3}"/>
                    <hr/><apex:outputtext value="{!item.account3}"/>
                    <hr/><apex:outputtext value="{!item.email3}"/>
                </apex:column>
                </apex:datatable>




 
Lukas Razim 29Lukas Razim 29
Hi David,
Thanks and sorry to bother again. We are on proffesional edition, this might work however I cannot use any logic written in apex due to this edition limitations. Do you think there is any possible way to get this using VF page only. Thanks very much
David ZhuDavid Zhu
This would work.
 
<apex:variable value="{!0}" var="counter0"/>
    <apex:variable value="{!0}" var="counter1"/>
    <apex:variable value="{!0}" var="counter2"/>
    

    <table>
        <tr>
            <td>
                <apex:dataTable value="{!members}" var="item">
                    <apex:column>
                    <apex:outputPanel layout="block" rendered="{!(MOD(counter0, 3) == 0)}">
                        <apex:outputText value="{!(item.contact)}"/> <br/>
                        <apex:outputText value="{!(item.account)}"/> <br/>
                        <apex:outputText value="{!(item.email)}"/> <br/>
                    </apex:outputPanel>
                        <apex:variable var="counter0" value="{!counter0 + 1}"/>
                    </apex:column>
                </apex:dataTable>
            </td>
            <td>
                <apex:dataTable value="{!members}" var="item">
                    <apex:column>
                    <apex:outputPanel layout="block" rendered="{!(MOD(counter1, 3) == 1)}">
                        <apex:outputText value="{!(item.contact)}"/> <br/>
                        <apex:outputText value="{!(item.account)}"/> <br/>
                        <apex:outputText value="{!(item.email)}"/> <br/>
                    </apex:outputPanel>
                        <apex:variable var="counter1" value="{!counter1 + 1}"/>
                    </apex:column>
                </apex:dataTable>
            </td>
            <td>
                <apex:dataTable value="{!members}" var="item">
                    <apex:column>
                    <apex:outputPanel layout="block" rendered="{!(MOD(counter2, 3) == 2)}">
                        <apex:outputText value="{!(item.contact)}"/> <br/>
                        <apex:outputText value="{!(item.account)}"/> <br/>
                        <apex:outputText value="{!(item.email)}"/>    <br/>
                    </apex:outputPanel>
                        <apex:variable var="counter2" value="{!counter2 + 1}"/>
                    </apex:column>
                </apex:dataTable>
            </td>
            
        </tr>
        
    </table>