I have used paneldgrid to create a table with VF where field values are fetch from the Lead object.

How can I create a custom controller to query the data base and bring field values from the Lead object that will populate the grid cells?

I need to iterate over the Lead object so is it the best way to do this by using a repeat component? (I want to bring the corresponding field values to Status, Name, Phone, and Comments Line 1)

If anyone can help with some code I would really appreciate it!! thanks!!

Here it's the VF code I have so far:

<apex:page StandardController="Lead">
padding: 5px;
.myHeader {
background: #cecece;
font-weight: bold;

<!-- Report Title - Date-->
<apex:panelGrid width="100%" cellpadding="0" cellspacing="0" rules="all">
<apex:outputText value="Title- Date"/> 

<!-- The table-->
<apex:panelGrid columns="2" width="100%" cellpadding="0" cellspacing="0" rules="all">

<!-- Status column -->
<apex:outputPanel style="padding:5px;" layout="block" styleClass="myHeader">
<apex:outputText value="Status"/>

<!-- Name - Phone column-->
<apex:outputPanel style="padding:5px;" layout="block" styleClass="myHeader">
<apex:outputText value="Name - Phone"/>

<!-- Status field value -->
<apex:outputPanel style="padding:5px;" layout="block">
<apex:outputText value="{!lead.status}"/> 

<!-- Name - Phone field value-->
<apex:outputPanel style="padding:5px;" layout="block">
<apex:panelGrid width="100%" cellpadding="0" cellspacing="0" rules="all">
<apex:outputText value="{!lead.name}"/> 
<apex:outputText value="{!lead.phone}"/> 


<!-- Comments Lines 1-->

<apex:outputText value="Comments Line 1"/>

  • sorry code is not found ?Welcome to stackexchange!Could you please post complete code to help with! – Mohith Shrivastava Jul 3 '13 at 16:11

A apex:panelGrid will render any apex:repeat elements in a single table cell, and placing apex:panelGrid inside a apex:repeat will render multiple tables. If your goal is one lead per table row, use a apex:dataTable or apex:pageBlockTable. If your goal is several records per row, you'll have to organize your data in the aforementioned tables, perhaps with a wrapper class. apex:panelGrid is designed to lay out non-repeating elements in a HTML table dynamically.

<apex:pageBlockTable value="{!leads}" var="record">
    <apex:column headerValue="Name" value="{!record.Name}"/>
    <apex:column headerValue="Status" value="{!record.status}"/>
    <apex:column headerValue="Email" value="{!record.email}"/>

The difference between apex:dataTable and apex:pageBlockTable is styling/formatting. The former renders as a normal HTML table, while the other renders in a fashion that looks like a related list (shaded header columns, row highlighting, etc).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.