salesforce
  1. salesforce-apex-column-component

apex:column Component

The apex:column component is used in Visualforce pages in Salesforce to define a table column in which data is displayed.

Syntax

The syntax for the apex:column component is as follows:

<apex:column
   headerValue="columnHeader"
   value="{!fieldName}"
   styleClass="cssClass">
  <!-- column content -->
</apex:column>

Example

Consider the following example:

<apex:page standardController="Account">
  <apex:pageBlock title="Account Contacts">
    <apex:pageBlockTable value="{!account.Contacts}" var="contact">
      <apex:column value="{!contact.Name}"/>
      <apex:column value="{!contact.Email}"/>
      <apex:column value="{!contact.Phone}"/>
    </apex:pageBlockTable>
  </apex:pageBlock>
</apex:page>

This example displays a table of Contacts related to an Account, with three columns for Name, Email, and Phone.

Output

The output of the example will be a table of Contacts related to the specified Account, with columns for Name, Email, and Phone.

Explanation

The apex:column component is used inside apex:pageBlockTable to define a single column in a table that displays data. The value attribute specifies the value to be displayed in the column, which is populated with data from the specified field in the specified object ({!contact.Name} in the example). The headerValue attribute specifies the column header text to be displayed at the top of the column, and the styleClass attribute specifies the CSS class to be applied to the column.

Use

The apex:column component is used in Visualforce pages to display data in table columns. It can be used with the apex:pageBlockTable component to display data from objects in Salesforce, or with other custom components and visualforce tags.

Important Points

  • Each apex:column component must be enclosed within an apex:pageBlockTable component to create a table.
  • The value attribute of the apex:column component specifies the field that is displayed in that column.
  • The headerValue attribute specifies text to be displayed in the column header.
  • The styleClass attribute specifies the CSS class to be applied to the column.

Summary

The apex:column component is a useful tool for displaying data in table columns on Visualforce pages in Salesforce. It can be used to populate the values in the column with data from object fields, and to specify column headers and CSS class. By using this component with apex:pageBlockTable component, developers can easily create tables that display data in a simple and elegant way.

Published on: