+ Start a Discussion
Chad RitchieChad Ritchie 

Basic Visualforce DataTable Filter

Hey Salesforce Community, 

Does anyone know how I could add a simple filter to both of these datatables? 

For example the first one I'd like to add a filter allowing only balances__c>0 only. 

I'm using a standard controller, and would ideally like to avoid using a custom controller to solve this. 

  <table>
    <tr>
    <td>
         <apex:dataTable value="{!Contact.Positions__r}" var="b" rules="all" columns="3" columnsWidth="250px,250px" align="left"
        columnClasses="columnBorders" headerClass="dataTableHeader" cellpadding="5px" cellspacing="0">
            <apex:column value="{!b.Product__r.Name}" headerValue="Product" /> 
             <apex:column value="{!b.Name}" headerValue="Account Name"/>
             <apex:column value="{!b.Balance__c}" headerValue="Balance"/> 
         </apex:dataTable>
         </td>
         <td>
         <apex:dataTable value="{!Contact.Transactions__r}" var="b" rules="all" columns="3" columnsWidth="250px,250px" align="left"
         columnClasses="columnBorders" headerClass="dataTableHeader" cellpadding="5px" cellspacing="0">
             <apex:column value="{!b.Product__r.Name}" headerValue="Product" /> 
             <apex:column value="{!b.Investor_Account_Name__c}" headerValue="Account Name"/>
             <apex:column value="{!b.Gross_Amount__c}" headerValue="Gross Amount"/> 
         </apex:dataTable>
      </td>
    </tr>
    </table>



Thanks!
Best Answer chosen by Chad Ritchie
Agustin BAgustin B
whoops I misread.
Do the rendered in the columns then:
<table>
    <tr>
    <td>
         <apex:dataTable value="{!Contact.Positions__r}" var="b" rules="all" columns="3" columnsWidth="250px,250px"         align="left"
        columnClasses="columnBorders" headerClass="dataTableHeader" cellpadding="5px" cellspacing="0">
             <apex:column value="{!b.Product__r.Name}" headerValue="Product" rendered="{!b.Balance__c>0}"/> 
             <apex:column value="{!b.Name}" headerValue="Account Name" rendered="{!b.Balance__c>0}"/>
             <apex:column value="{!b.Balance__c}" headerValue="Balance" rendered="{!b.Balance__c>0}"/> 
         </apex:dataTable>
      </td>

Good luck and if it helps please mark as correct so the question can be solved for others.

All Answers

Agustin BAgustin B
HI Chad, inside the datatable sorround the columns with this with your condition
<apex:outputText rendered="{!Contact.Balance__c>0}"> 
<apex:column value="{!b.Product__r.Name}" headerValue="Product" /> 
             <apex:column value="{!b.Name}" headerValue="Account Name"/>
             <apex:column value="{!b.Balance__c}" headerValue="Balance"/> 

</apex:outputText>
if this helps, please mark as correct, it may help others
 
Chad RitchieChad Ritchie
Agustin thanks for the quick response! 

I tried this:
 
<table>
    <tr>
    <td>
         <apex:dataTable value="{!Contact.Positions__r}" var="b" rules="all" columns="3" columnsWidth="250px,250px"         align="left"
        columnClasses="columnBorders" headerClass="dataTableHeader" cellpadding="5px" cellspacing="0">
             <apex:outputText rendered="{!b.Balance__c>0}"> 
             <apex:column value="{!b.Product__r.Name}" headerValue="Product" /> 
             <apex:column value="{!b.Name}" headerValue="Account Name"/>
             <apex:column value="{!b.Balance__c}" headerValue="Balance"/> 
           </apex:outputText>
         </apex:dataTable>
      </td>
        

But I seemed to get this error: <apex:column> must be the direct child of either <apex:dataTable> or <apex:pageBlockTable>

Any idea on that?

 
Agustin BAgustin B
Hi, why the  <i><u><b>? it has to be under apex:datatable if not you are going to get that error.
<table>
    <tr>
    <td>
         <apex:dataTable value="{!Contact.Positions__r}" var="b" rules="all" columns="3" columnsWidth="250px,250px"         align="left"
        columnClasses="columnBorders" headerClass="dataTableHeader" cellpadding="5px" cellspacing="0">
           <apex:outputText rendered="{!b.Balance__c>0}">
             <apex:column value="{!b.Product__r.Name}" headerValue="Product" /> 
             <apex:column value="{!b.Name}" headerValue="Account Name"/>
             <apex:column value="{!b.Balance__c}" headerValue="Balance"/> 
           </apex:outputText>
         </apex:dataTable>
      </td>


If it helps please like or mark a correct.

Good luck!
Chad RitchieChad Ritchie
Sorry not sure why the <i><u><b> thing popped up when I copied this over. 

Still seem to be getting that error though, seems to be implying that the <column> must be right below the DataTable, and therefore the outputtext is getting in the way? 

I appreciate the help!
Agustin BAgustin B
whoops I misread.
Do the rendered in the columns then:
<table>
    <tr>
    <td>
         <apex:dataTable value="{!Contact.Positions__r}" var="b" rules="all" columns="3" columnsWidth="250px,250px"         align="left"
        columnClasses="columnBorders" headerClass="dataTableHeader" cellpadding="5px" cellspacing="0">
             <apex:column value="{!b.Product__r.Name}" headerValue="Product" rendered="{!b.Balance__c>0}"/> 
             <apex:column value="{!b.Name}" headerValue="Account Name" rendered="{!b.Balance__c>0}"/>
             <apex:column value="{!b.Balance__c}" headerValue="Balance" rendered="{!b.Balance__c>0}"/> 
         </apex:dataTable>
      </td>

Good luck and if it helps please mark as correct so the question can be solved for others.
This was selected as the best answer