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
Mike ChandlerMike Chandler 

Is it possible to render groupings in an apex:dataTable?

I have a custom object that includes a picklist field of Category with three possible values: Hot, Warm, Cold.  I want to display a list of custom objects using an apex:dataTable in my custom Visualforce page, but I would like to group my output by Category.  I'm wondering if there's a function in the dataTable that allows me to render groupings of rows separated by a row with a single column that renders just the Category name of the matching items below it.

For example:
  • Hot
  • Item 1 - columns of data
  • Item 2 - columns of data
  • Warm
  • Item 3 - columns of data
  • Item 4 - columns of data
  • Item 5 - columns of data
  • Cold
  • Item 6 - columns of data
Alain CabonAlain Cabon
Hi,

A common trick is to use breakBefore  of  <apex:column>

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_column.htm
 
<apex:page standardController="Account" >
  <apex:dataTable value="{!Account}" var="acc">
      <apex:column  headerValue="Hot"/>
      <apex:column breakBefore="true">
          <apex:dataTable value="{!Account.contacts}" var="cnt">
              <apex:column value="{!cnt.name}"/>
          </apex:dataTable>
      </apex:column>
      <apex:column  headerValue="Warn"/>
  </apex:dataTable>  
</apex:page>
Raj VakatiRaj Vakati
Yes, I can say. But what you need to do it  is prepare the List<WrapperClass> with the format you wanted to show and iterate on the wrapper class 
 
List<WrapperClass> str = new List<WrapperClass>

str.add(Hot);
str.add(Item 1 - columns of data)
str.add(Item 2 - columns of data)
str.add(Warm)
str.add(Item 3 - columns of data)
str.add(Item 4 - columns of data)
str.add(Item 5 - columns of data)
str.add(Cold)
str.add(Item 6 - columns of data)