salesforce
  1. salesforce-apex-datatable-component

apex:dataTable Component

The apex:dataTable component in Visualforce allows you to display data in a table format, with columns representing data fields and rows representing data records. It is a powerful tool for organizing and presenting data in a comprehensive and user-friendly way.

Syntax

The apex:dataTable component has the following syntax:

<apex:dataTable value="valueName" var="varName">
    <!--
    Define columns and headers here
    -->
</apex:dataTable>

Example

Suppose we have a custom object named Product__c in our Salesforce org that has fields such as Name, Price__c, Description__c, and Image_URL__c. We can use the apex:dataTable component to create a table to display this data as follows:

<apex:dataTable value="{!products}" var="p">
    <apex:column headerValue="Name" value="{!p.Name}"/>
    <apex:column headerValue="Price" value="{!p.Price__c}"/>
    <apex:column headerValue="Description" value="{!p.Description__c}"/>
    <apex:column headerValue="Image" value="{!p.Image_URL__c}"/>
</apex:dataTable>

Here, we have defined the data source for the table as a variable named products and have specified the variable p as the iterator variable. We have created four columns to display the Name, Price__c, Description__c, and Image_URL__c fields of each Product__c record.

Explanation

In the example above, the apex:dataTable component displays data from the Product__c object in tabular format with each row representing a Product__c record and each column representing a field of the object. The value attribute specifies the data source for the table, while the var attribute specifies the iterator variable to be used in the table. The apex:column component is used to define each column of the table, with the headerValue attribute specifying the column header and the value attribute specifying the field to be displayed in the column.

Use

The apex:dataTable component can be used to display data from any standard or custom object in Salesforce. It is a versatile tool for organizing and presenting data in a user-friendly way, and can be customized to suit your specific needs.

Important Points

  • The value attribute of the apex:dataTable component must evaluate to an iterable data type such as a list or set.
  • The var attribute specifies the iterator variable to be used in the table, and is used to access individual data records within the table.
  • The apex:column component is used to define the columns of the table, with the headerValue attribute specifying the column header and the value attribute specifying the field to be displayed in the column.

Summary

The apex:dataTable component in Visualforce is a powerful tool for organizing and presenting data in a table format. It can be used to display data from any standard or custom object in Salesforce, and is a versatile tool for creating user-friendly interfaces for data management. The value and var attributes are used to specify the data source and iterator variable for the table, while apex:column components are used to define the table columns and headers.

Published on: