0

We have the code below that we are using to create a list of products that were added to an order. I want to remove a single product code from the list and render everything else. How can we do that?

<apex:repeat value="{!Order.OrderItems}" var="cx">
                <!-- class="table_tr_td"-->
                <tr>
                    <td style = "width:15%;border: 1px solid black;padding: 5px;text-align: center;font-size:14px;">
                        <apex:outputText rendered="{!IF(cx.Order.PoNumber == Null,False,IF(cx.Order.PoNumber == '0000',False,True))}">{!cx.Order.PoNumber}</apex:outputText> 
                        <apex:outputText rendered="{!IF(cx.Order.PoNumber == Null,True,IF(cx.Order.PoNumber == '0000',True,False))}">{!cx.Order.OrderNumber}</apex:outputText>     
                    </td>
                    <td style = "width:10%;border: 1px solid black;padding: 5px;text-align: center;font-size:14px;">{!cx.Total_Units__c }</td>
                    <td style = "width:15%;border: 1px solid black;padding: 5px;text-align: center;font-size:14px;">{!cx.Product2.Harmonized_Code__c}</td>
                    <td style = "width:15%;border: 1px solid black;padding: 5px;text-align: center;font-size:14px;">{!cx.Product2.ProductCode}</td>
                    <td style = "width:20%;border: 1px solid black;padding: 5px;text-align: center;font-size:14px;">{!cx.Product2.Description}</td>
                    <td style = "width:15%;border: 1px solid black;padding: 5px;text-align: center;font-size:14px;">
                        <apex:outputText value="{0, number, ###,###,###,##0.00}">
                            <apex:param value="{!cx.PricebookEntry.UnitPrice}" />
                        </apex:outputText>
                    </td>
                    <td style = "width:15%;border: 1px solid black;padding: 5px;text-align: center;font-size:14px;">
                        <apex:outputText value="{0, number, ###,###,###,##0.00}">
                            <apex:param value="{!cx.Total_Price__c}" />
                        </apex:outputText>
                    </td>

1 Answer 1

1

I think you might be best off with taking care of that in the controller. Create a getter method to give you only the lines you want to show.

Normally you'd wrap the code you need to render conditionally in an outputPanel, but that's an extra div you can't really have inside a table.

Alternatively have a look at this post, it may have some ideas: https://stackoverflow.com/questions/1144123/how-can-i-hide-an-html-table-row-tr-so-that-it-takes-up-no-space

UPDATE: you could try to add a conditional style to your tag like this: <tr style="{! if(cx.ProductCode == 'xx', 'display:none;', ''}"> But this is going to get ugly as you get more different codes you want to exclude.

7
  • I apologize that I am very new to this and do not really understanding coding. This was created by somebody else in the past. Could you please explain the getter method in a little more detail? I'm not sure if it is something that I should change at the beginning: <apex:page standardController="Order" renderAs="pdf"> <apex:stylesheet value="{!URLFOR($Resource.CInvoice, 'CInvoice.css')}"/> Commented Jan 3, 2020 at 22:01
  • No worries :-) Your page is using the Standard Apex Controller, you would have to create a new Apex class and use that as the "Extension". But if you are not a programmer you probably don't want to try and do that yourself. Trying to hide the row with CSS may be easier if you are familiar with that, but I'm not very good at that myself. I'll update my answer with one suggestion, but i have to admin I've not tried it and it may need tweaking.
    – alesremta
    Commented Jan 3, 2020 at 22:12
  • 1
    @packo_cz, your update should be the quickest way to do this, but the syntax looks off: <tr style="{! if(cx.ProductCode == 'xx', 'display:none;', '')}">
    – nbrown
    Commented Jan 3, 2020 at 22:33
  • Thanks @nbrown, my mistake. Updated the answer accordingly
    – alesremta
    Commented Jan 5, 2020 at 12:42
  • <rendered="{! if(cx.Product_Code__c == 'Shipping and Handling', 'display:none;', '')}"/> I will only want to exclude a single code (Shipping and Handling), so if I can get this code to work, that would be great. I modified what you shared (based on our fields). However, I cannot find where to enter this code - it is only either moving the fields in the table or just not doing anything. Where exactly should it be entered? Commented Jan 6, 2020 at 14:36

You must log in to answer this question.

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