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
Sid LightningSid Lightning 

Hide entire column and row on pdf if the value in row is 0

Hi,

I want to hide a field in visualforce page pdf , if there is no value or '0' in it.

However, heading for the field is given in an HTML Tag ? I want that also to be hidden.

This is how code is written.

<th class="centerCell">SMD</th>

<apex:repeat value="{!Opportunity.OpportunityLineItems}" var="l">
<tr>
<td class="attCell centerCell">{!l.Discount__c}</td>
</tr>
</apex:repeat>

Please note that thier are other fields also in the same row. But I want just the value to get hidden for this field
Deepesh Rao 9Deepesh Rao 9
Can you try using apex:outputtext and apply the styleclass attribute for applying styles and rendered attribute to hide or show the fields based on some criteria
 
Dushyant SonwarDushyant Sonwar
Hi Sid ,

This is how i understood your question , you want to hide a SMD header in table if all the values discount is 0 .
If this is what you want,

Then this will be bit  complex , you need to restructure your apex class and get total in the apex

I have made small example for you .
 
<apex:page controller="DemoNumberController">

<table border="1">
<th class="centerCell" style="{!If(wrapperObj.totalDiscount == 0 ,'display:none;' ,'' )}">SMD</th>

<apex:repeat value="{!wrapperObj.discountList}" var="numberObj">
<tr style="">
<td class="attCell centerCell">{!numberObj}</td>
</tr>
</apex:repeat>
</table>

</apex:page>
 
public class DemoNumberController{
    public IntegerWrapper wrapperObj{get;set;}
    public DemoNumberController(){
        wrapperObj = new IntegerWrapper();
        
    }
    public class IntegerWrapper{
        public Integer totalDiscount{get;set;}
        public list<Integer> discountList{get;set;}
        public IntegerWrapper(){
            discountList = new list<Integer>{0 , 0 , 0 , 0};
            totalDiscount = 0;
            for(Integer numberObj : discountList ){
                totalDiscount += numberObj ==null ? 0 : numberObj;
            }
        }

    }
}

You can refactor this code and use opportunitylineItem in repace of discountList.
Hope this helps.