Search code examples
jsfprimefaceshtml-tabledata-export

How to export datatable in HTML format?


I am using primefaces 5.0 jar files. I searched on google and found that primefaces datatable is not supported to export html format. its support only csv, xls, pdf and xml format. but i want to achieve this functionality so any one know how to achieve this functionality.

Is there any alternative way to export datatable in html format?


Solution

  • It is not to difficult to add an additional format to the PrimeFaces exporter.

    Just override two classes in PrimeFaces (you can put the overridden classes in your own application with the same name and package):

    In the first you add "HTML" and in the second you add an additional case in the switch:

    case HTML:
        exporter = new HTMLExporter();
    break;
    

    This HTMLExporter does not exist, and you need to use one of the existing exporters as an example to create your own HTMLExporter (if you put it in a different package than org.primefaces.component.export, you might need to also add an import statement in the ExporterFactory, but that is hopefully obvious)