1

Anybody know how to display headers in rows? For example:

Header   Value
======   =====
Name     Joe Smith
Address  111 North First St.
City     Los Angela

I have tried

<apex:column headerValue="Name">
    <apex:outputField value="{!accDetail.Name}"/>
</apex:column>
<apex:column headerValue="Target Account">
    <apex:outputField value="{!accDetail.Target_Account__c}"/>
</apex:column>

2 Answers 2

3

Here is the visualforce page:

<apex:page controller="tableController">
  <apex:pageMessages></apex:pageMessages> 
    <apex:pageBlock>
 <apex:pageBlockTable value="{!mapToDisplayonUI}" var="nameOfField">
  <apex:column value="{!mapToDisplayonUI[nameOfField]}" headerValue="Field Name/ Record Name"/>
  <apex:repeat value="{!posList}" var="posRec">
      <apex:column value="{!posRec[nameOfField]}">
          <apex:facet name="header">
              <apex:outputText value="{!posRec['name']}"/>
          </apex:facet>
      </apex:column>
  </apex:repeat>
 </apex:pageBlockTable>
</apex:pageBlock>
 </apex:page>

Here is the controller associated with the page:

public with sharing class tableController{
public List<Position__c> posList{get;set;}
public Map<String, String> mapToDisplayonUI{get;set;}


public tableController(){
    posList = new List<Position__c>();
    mapToDisplayonUI = new Map<String, String>();
    posList = [select id, name, name__c, salary__c from Position__c LIMIT 5];
    mapToDisplayonUI.put('Id', 'Record ID');
    mapToDisplayonUI.put('name__c', 'Name');
    mapToDisplayonUI.put('salary__c', 'Salary');
}}

You can also modify this code for any other object, and there is some code which is static in this given code, which you make dynamic on your own. The whole idea was to have a Map of fieldNames (API Name) and then using the syntax on visualforce page to get the value of that field from record queried in SOQL.

Below is the output:

Expected Output

1
  • Hey thanks Nitish. This is exactly what I as looking for.
    – user7123
    Commented Jun 6, 2015 at 0:14
1

Not sure what's wrong with headerValue, but you can also use a facet.

<apex:column>
    <apex:facet name="header">Name</apex:facet>
    <apex:outputField value="{!accDetail.Name}" />
</apex:column
2
  • Thanks for the help, but I need to show my headers all in one column and the data in the next column.
    – user7123
    Commented Jun 3, 2015 at 2:53
  • Ah. Makes more sense now.
    – Adrian Larson
    Commented Jun 3, 2015 at 3:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .