Search code examples
htmlcsssalesforceapexvisualforce

VF: Is it possible to show only specific rows in datatable?


I have a datatable based on the OpportunityLineItems Object that shows every Product in the Opportunity Record. Now I want only the products to be shown that are selected by a checkbox. Is there a possibility to render only specific rows in pure Visualforce? Something like <apex:DataTable renderrow="{!Oli.Checkbox == True}?

I only have a Professional licence, so Apex Code isnt available. Is there a possibility to only do this in VF on clientside? Maybe JavaScript could also work..

Here is my Code:

<apex:variable var="index" value="{!1}"/>
                        <apex:dataTable width="100%" value="  !Opportunity.OpportunityLineItems}" var="oli"
                            <apex:column width="10%" headerClass="tableheaderleft"  styleClass="tablebodycenter">
                                <apex:outputLabel value="{!index}."/>
                                <apex:variable var="index" value="{!index+1}"/>
                                <apex:facet name="header"></apex:facet>
                             </apex:column>
                            <apex:column width="40%" headerClass="tableheaderleft"  styleClass="tablebodyleft">
                                <apex:facet name="header">Bezeichnung</apex:facet>
                                <apex:OutputField value="{!oli.Name}"/> <br/>
                                    <table border="0" width="100%" style="border-collapse: collapse; margin-bottom:10px">
                                        <tr><td width="30%" style="padding: 0px;line-height: 100%;"><strong>Leistungszeitraum:</strong>&nbsp;<br></br><apex:outputText value="{0, date, dd.MM.yyyy}">
                                            <apex:param value="{!oli.ServiceDate}" /> </apex:outputText>&nbsp;-&nbsp;<apex:outputText value="{0, date, dd.MM.yyyy}">
                                            <apex:param value="{!oli.Licensing_Period_Calculated__c}" /> </apex:outputText></td></tr>
                                    </table>
                             </apex:column>
                            <apex:column width="10%" headerClass="tableheadercenter" footerClass="tablefootercenter" styleClass="tablebodycenter">
                                <apex:facet name="header">Anzahl</apex:facet>
                                <apex:OutputField value="{!oli.Quantity}"/>
                                <apex:facet name="footer"></apex:facet>
                            </apex:column>
                            <apex:column width="20%" headerClass="tableheadercenter"  styleClass="tablebodycenter">
                                <apex:facet name="header">Einzelbetrag</apex:facet>
                                <apex:OutputField value="{!oli.UnitPrice}"/>
                                <apex:facet name="footer"></apex:facet>
                            </apex:column>
                            
                            <apex:column rendered="{!Opportunity.TotalDiscount__c != 0}" headerClass="tableheadercenter" footerClass="tablefootercenter" styleClass="tablebodycenter">
                                <apex:facet name="header">Rabatt</apex:facet>
                                <apex:OutputField value="{!oli.Discount}"/>
                                <apex:facet name="footer"></apex:facet>
                            </apex:column>  
                            
                            <apex:column width="20%" headerClass="tableheaderright"  styleClass="tablebodyright">
                                <apex:facet name="header">Gesamtbetrag</apex:facet>
                                <apex:OutputField value="{!oli.TotalPrice}"/>
                                <apex:facet name="footer"></apex:facet>
                            </apex:column>                                                                                            
                        </apex:dataTable>

to be as prezise as possible: I dont want the whole column to be hidden. If I have this list of elements from the same column:

Element 1 (with checkbox checked)
Element 2 (with checkbox not checked)
Element 3 (with checkbox checked)

Then I want the Datatable to output only 2 rows, one for Element 1 and one for Element 3. So the row for Element 2 should not be rendered.


Solution

  • Not with "apex:datatable", that one is very all-or-nothing, you can conditionally render columns but not rows. Try to hand-craft the table using "apex:repeat", output the<tr>, <td>etc raw html in a loop. You can wrap the single row's html in apex:output panel rendered=... Or apex:variable with same condition

    (I'm on mobile, apologies for formatting. Poke me later if you're still stuck)