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
Arek S.Arek S. 

What kind of object does DataTable work with?

I'm creating a DataTable but I will be feeding it data from a created object in my controller but I will not be using the SELECT SQL command.  What kind of object do I have to create in my controller to work with the DataTable?  I'm assuming it's going to be a List, but a list of what?  A list of class objects with just variables?

 

Thanks.

 

P.S.  I'm quite new to Visualforce ... hence this question.

Best Answer chosen by Admin (Salesforce Developers) 
aballardaballard

You need to define the classLOData so that the data members either have getter/setter methods or are definedusing the apex property syntax .    Just public members doesn't work.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_properties.htm#kanchor354

 

All Answers

colemabcolemab

I think it has to be a collection, but doesn't have to be a list.

 

Here is info about a list:

 

"A list is an ordered collection of typed primitives, sObjects, user-defined objects, Apex objects or collections that are distinguished by their indices."

 

See documentation here.

Arek S.Arek S.

Thanks, I know what a List is, but the question I have is a List containing what kind of objects will work with the DataTable on a Visualforce page.  Hope that clarifies things a little.

 

Thanks.

colemabcolemab

Any colletion (List, Map, Set) should work with data table. List can be (but are not limited to):

primitives (think int, string, etc)

sObjects (any standard or custom object in the database)

Apex objects (object you make from a custom class)

 

Does this make sense?

aballardaballard

The list can contain any kind of objects with fields to use for the columns.  Sobjects, or Apex objects.  Apex class can use get/set property definitions or it can define getter/setter methods. 

 

 

Arek S.Arek S.

I'm thinking there must be something I'm missing cause I'm new to Visualforce, so I think some code examples will be best ...

 

Here's what my Visualforce page code looks like:

<apex:page Controller="MarketingReports">
  <apex:datatable value="{!LeadsAndOpportunitiesDataList}" var="LOData" rules="all" cellpadding="5%">
    <apex:column value="{!LOData.name}" headerValue="Campaign Name"/>
    <apex:column value="{!LOData.leadsOpen}" headerValue="Leads - Open"/>
    <apex:column value="{!LOData.leadsInProgress}" headerValue="Leads - In Progress"/>
  </apex:datatable>
</apex:page>

 And here's what my controller looks like:

public with sharing class MarketingReports
{
  public class LOData
  {
    // Data
    public string name;
    public string leadsOpen;
    public string leadsInProgress;
  }

  // Method that returns a list of leads and opportunities data for the report
  public LOData[] getLeadsAndOpportunitiesDataList()
  {
    // Create a list to hold the leads and opportunities data
    List<LOData> LOReport = new List<LOData>();
  
    // Fill LOReport with data	
  
    return LOReport;
  }
}

 Unfortunately with the above code I get a "unknown property" error.

 

What do I need to change in this code to make it work?

 

Thank you for all the help.

aballardaballard

You need to define the classLOData so that the data members either have getter/setter methods or are definedusing the apex property syntax .    Just public members doesn't work.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_properties.htm#kanchor354

 

This was selected as the best answer