jsfprimefacesexportprimefaces-datatable

Customize export output format of p:dataTable


I have a Primefaces dataTable where one column is having three output texts and one command button with tooltip. The button appears with output labels as

This is for export label. This is for text.org.primefaces.component.commandbutton.CommandButton@3f60d3f9

How can I not include/print this command button with tooltip to export the dataTable to excel?

I can't move the command button to new column for business case.


Solution

  • In PrimeFaces you can override the exported content of a column by using the exportFunction attribute (which is in the documentation). If you'd read this in the documentation, you'd easily have found https://forum.primefaces.org/viewtopic.php?t=50284 by using google. In it, an example is given of how to override the 'exported value' of a column:

    XHTML:

    <p:column exportFunction="#{testView.exportBrand}">
       <f:facet name="header">
           <h:outputText value="Brand" />
      </f:facet>
      <h:outputText value="#{car.brand}" />
    </p:column>
    

    Java:

    public String exportBrand(UIColumn column) {
        String value = "";
        for(UIComponent child: column.getChildren()) {
            if(child instanceof ValueHolder) {
                value = ComponentUtils.getValueToRender(FacesContext.getCurrentInstance(), child);
            }
        }
        
        return value + "_TEST";
    }
    

    Just extend this and in the for loop only export things you want to export.