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
Ross JamesRoss James 

Visualforce Email - How to filter datatable?

 

<apex:datatable align="left" var="nt" width="100%" value="{!relatedTo.Network_Trial_Items__r}">
            <apex:column width="40%" value="{!nt.Product__c}" headerValue="Product"/>
            <apex:column width="30%" value="{!nt.USIM__c}" headerValue="USIM"/>
</apex:datatable>

The above gives me a great table of related items, but I need to filter and only show a specific category. 

 

 

How do we do this in a Visualforce email? 

Best Answer chosen by Admin (Salesforce Developers) 
sebcossebcos

Hi Ross,

you can filter columns by using an outputpanel and the rendered attribute, for example to list opportunities which are not closed won:

 

<messaging:emailTemplate subject="test" recipientType="Contact" relatedToType="Account">
<messaging:htmlEmailBody >
<table>
  <apex:repeat value="{!relatedTo.Opportunities}" var="o">
     
      <apex:outputPanel rendered="{!NOT(o.stagename='Closed Won')}">
          <tr>
           <td> {!o.name}      </td>
           <td> {!o.stagename} </td>
          </tr>
       </apex:outputPanel>
  </apex:repeat>
  </table>
</messaging:htmlEmailBody> 
</messaging:emailTemplate>

 the column tag also has a rendered attribute but does not want to be included in nothing but datatable or pageblocktable.

That is why I am using plain html to create the table.

Note that you could add your filter directly on the column tags but that is not very elegant.

 

 

All Answers

sebcossebcos

Hi Ross,

you can filter columns by using an outputpanel and the rendered attribute, for example to list opportunities which are not closed won:

 

<messaging:emailTemplate subject="test" recipientType="Contact" relatedToType="Account">
<messaging:htmlEmailBody >
<table>
  <apex:repeat value="{!relatedTo.Opportunities}" var="o">
     
      <apex:outputPanel rendered="{!NOT(o.stagename='Closed Won')}">
          <tr>
           <td> {!o.name}      </td>
           <td> {!o.stagename} </td>
          </tr>
       </apex:outputPanel>
  </apex:repeat>
  </table>
</messaging:htmlEmailBody> 
</messaging:emailTemplate>

 the column tag also has a rendered attribute but does not want to be included in nothing but datatable or pageblocktable.

That is why I am using plain html to create the table.

Note that you could add your filter directly on the column tags but that is not very elegant.

 

 

This was selected as the best answer
Ross JamesRoss James

Secbos, it worked like a charm, thanks so much.

hawkmoon82hawkmoon82

Secbos, what about if need to show only Opportunities in a specific stage?

Thx

hawkmoon82hawkmoon82

Sorry.. I didn't read the code correctly... ! means equal !NOT means different...