Conditionally show table column headings Is there a way to conditionally display a table column heading if the table field row has been entered? i.e.

if my table has up to 3 columns
and I fill in ALL the fields like this I'd see

ch1 | ch2 | ch3

a   |  b  |  c

but, if I only fill in 2 columns without conditionals I'd see this

ch1 | ch2 | ch3

a   |  b  |  

I'd like to conditionally only show the column headings/rows populated like this:

ch1 | ch2 |

a   |  b  |  

Is that possible?
This works for me:

{% set showCol1 = false %}
{% set showCol2 = false %}
{% set showCol3 = false %}
{% set showCol4 = false %}
{% set showCol5 = false %}


{% for row in entry.fieldname %}
{% if row.col1|length %}{% set showCol1 = true %}{% endif %}
{% if row.col2|length %}{% set showCol2 = true %}{% endif %}
{% if row.col3|length %}{% set showCol3 = true %}{% endif %}
{% if row.col4|length %}{% set showCol4 = true %}{% endif %}
{% if row.col5|length %}{% set showCol5 = true %}{% endif %}
{% endfor %}


&lt;table&gt;
&lt;thead&gt;
    &lt;tr&gt;
        {% if showCol1 %}&lt;th&gt;Col 1&lt;/th&gt;{% endif %}
        {% if showCol2 %}&lt;th&gt;Col 2&lt;/th&gt;{% endif %}
        {% if showCol3 %}&lt;th&gt;Col 3&lt;/th&gt;{% endif %}
        {% if showCol4 %}&lt;th&gt;Col 4&lt;/th&gt;{% endif %}
        {% if showCol5 %}&lt;th&gt;Col 5&lt;/th&gt;{% endif %}
    &lt;/tr&gt;
&lt;/thead&gt;
{% for row in entry.fieldname %}
    &lt;tr&gt;
        {% if showCol1 %}&lt;td&gt;{{ row.col1 }}&lt;/td&gt;{% endif %}
        {% if showCol2 %}&lt;td&gt;{{ row.col2 }}&lt;/td&gt;{% endif %}
        {% if showCol3 %}&lt;td&gt;{{ row.col3 }}&lt;/td&gt;{% endif %}
        {% if showCol4 %}&lt;td&gt;{{ row.col4 }}&lt;/td&gt;{% endif %}
        {% if showCol5 %}&lt;td&gt;{{ row.col5 }}&lt;/td&gt;{% endif %}
    &lt;/tr&gt;
{% endfor %}
&lt;/table&gt;