"No records found" doesn't take conditionally rendered column of p:dataTable into account

421 views Asked by At

I am currently having a minor problem with the rendered attribute of column in my dataTable using PrimeFaces 4.0. I have a column in my table which should not always be displayed, so I used its rendered attribute and fetching the value from my backing bean. This is the 6th and last column. The dataTable is inside a p:dialog which will be shown at the end of the method.

The rendered attribute seems to work correctly because when showColumn is false, the column will not be shown and vice versa, but there's an issue. As seen in the image, the "No records found." message can't seem to reach until the last column. When I try to remove the rendered attribute, or manually set it to true (not using the backing bean value), the "No records found." message will reach until the last column as expected.

The entire dialog/form containing these elements seem to be updated correctly after the ajax request.

Backing Bean method:

public void getStatus(final MyClass foo, boolean showColumn) {

    updateForm(foo);
    setShowColumn(showColumn);

    RequestContext.getCurrentInstance().execute("dailyStatus.show();");
}

Column Portion in xhtml:

<p:column headerText="Problematic Column" styleClass="tablecenter" rendered="#{myMBean.showColumn}">
    <p:commandLink id="view"
        action="#{myMBean.doSomething}" update="@form"
        rendered="#{obj.status.equals('FAILED')? 'true' : 'false'}"
        onclick="spin_start()" oncomplete="spin_stop()">
        <h:graphicImage name="images/restart.png" styleClass="icon" />
    </p:commandLink>
</p:column>

As Displayed on the Table: As displayed on page

1

There are 1 answers

1
ochiboy On BEST ANSWER

For PrimeFaces 4.0 there is a 'solution' where I resorted to a hack-ish fix to the problem using jQuery. For recent PrimeFaces versions this is already fixed

When the dynamic column needs to be displayed, I use flags in my backing bean then call this method. (and the list for the datatable should be null or empty, as mentioned in the issue)

RequestContext.getCurrentInstance().execute("$('[id=\"myForm:myDataTable\"] tr.ui-widget-content td').attr('colspan', 6);");

This forces the single td's colspan on the row after the header row to reach up to the last header column. Hope this helps others that encounter this issue in the future!