1


I have a table on a VF page that allows the users to filter, sort and choose which columns are visible. I accomplish the column visibility by using javascript to change the style to display:none. However, I need to allow the user to render this page as a pdf, meaning no more javascript. The headers are no problem, I just use an apex:repeat to iterate through a list of headers. For the data, I tried setting a boolean for each column and using an if to print tags with content. This didn't work, as it didn't like extraneous code outside of a tag. Instead, now I'm trying to nest 2 apex repeats, one through my roster of data, the other through the header. If I do this (to test functionality):

<apex:repeat value={!rosters} var="r">
   <tr>
      <apex:repeat value="{!showFields}" var="s">
           <td>{!r.First_Name__c)}</td>
      </apex:repeat>
   </tr>

...then every cell is filled with the last name. However, if I replace the cell declaration to this:

<td>{!IF(s=="FirstName",r.First_Name__c,s)}</td>

...it just prints a blank cell. It's not the test, as if I change it to s="fName" (false), it displays 'FirstName' in the cell, as it should. I feel like this is just some simple syntax issue, as I'm new to Salesforce. Any ideas?

1 Answer 1

3

A simpler approach is to make use of the map-like syntax available for SObjects (see the get/put in sObject Class). So if you arrange for the field API names that you want to show to be in a list called fields, this will display those fields:

<apex:repeat value={!rosters} var="r">
   <tr>
      <apex:repeat value="{!fields}" var="f">
           <td>{!r[f]}</td>
      </apex:repeat>
   </tr>
</apex:repeat>
1
  • Thanks! I feel like this should work, but instead it tells me "Invalid field Date_Of_Birth__c for SObject Roster__c". However, {!r.Date_Of_Birth__c } works just fine. Not sure what the issue is but I feel like I'm closer to making it work than I was....
    – user12315
    Commented Oct 14, 2014 at 19:18

You must log in to answer this question.

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