13

I am showing object fields by using <table>,<tr> and <td> tags in page to show the details in some format. I am using following condition to show data on the page, if field is not blank

<tr>
<td><apex:outputLabel rendered="if field is not blank"><td> 
</tr>

In this code, if field is blank data is not visible but that row is generated and I am getting blank row between two rows.

How to remove this row dynamically?

eyescream
  • 24,045
  • 5
  • 55
  • 92
Rahul Nagardalekar
  • 587
  • 1
  • 5
  • 16

3 Answers3

16

You should be able to control the rendering of the row using <apex:variable>:

<apex:variable var="v" value="" rendered="{!NOT(ISBLANK(TheField__c))}">
  <tr>
    <td><apex:outputLabel rendered="if field is not blank"><td> 
  </tr>
</apex:variable>

<apex:outputPanel> would probably also work as long as you specify layout="none"

Matt Lacey
  • 25,618
  • 7
  • 66
  • 149
  • 1
    Note that apex:variable is actually working better than apex:outputPanel. The outputPanel tag does give problems when conditionally hiding tr tags in PDFs. The table somehow breaks when using outputPanel but does not when using apex:variable. – Willem Mulder May 09 '18 at 09:47
13

I tend to do this directly in HTML with some CSS hackery

<tr style="display: {!IF(ISBLANK(Field__c), 'none', 'table-row')};">
    <td>Content of your cell</td>
</tr>
pjcarly
  • 7,451
  • 5
  • 36
  • 56
0

For group of elements we can use apex:outputPanel

<apex:outputPanel layout="none" rendered="{!NOT(ISBLANK(TheField__c))}">
  <tr>
    <td><apex:outputLabel rendered="if field is not blank"><td> 
  </tr>
  .
  .
  .
  .
  <tr>
    <td><apex:outputLabel rendered="if field is not blank"><td> 
  </tr>

</apex:outputPanel>
SANN3
  • 351
  • 7
  • 18