Printing Tables

Hi everybody,
is there any way for printing a Table in Vaadin?

I tried adding the Table on a new Window and executing javascript print(), but the resulting printed table is truncated


Window printWindow = new Window("Print");
printWindow.setSizeFull();

VerticalLayout layout = new VerticalLayout();
layout.setSizeFull();
layout.addComponent(myTable);

printWindow.setContent(layout);
getApplication().addWindow(printWindow);
getApplication().getMainWindow().open(new ExternalResource(printWindow.getURL()), "_blank");

printWindow.executeJavaScript("print();");

printWindow.executeJavaScript("self.close();");

Hi,

The table component doesn’t expose all its contents at once on the client side due to performance reasons (only a reasonable cache buffer is loaded). You could call table.setCacheRate(0d) in order to force the table to load all the contents (not sure if it will solve your issue though). Otherwise - maybe it makes sense to forst export the table in Excel and the print it. This could be done with
this
add-on.

HTH
Aleskandr

Thank you for your reply Aleskandr.

I’m trying to export table data as HTML, putting the table content as HTML on a Label component, with css styles. But when printing, the resulting printed document seems to be without styles.

This is the code I used:


Window printWindow = new Window("Print");
printWindow.setSizeFull();

// converti la Table in HTML
String html = "styled content here";

Label content = new Label(html,Label.CONTENT_XHTML);
content.setSizeFull();

VerticalLayout layout = new VerticalLayout();
layout.setSizeFull();
layout.addComponent(content);

printWindow.setContent(layout);
getApplication().addWindow(printWindow);
getApplication().getMainWindow().open(new ExternalResource(printWindow.getURL()), "_blank");
// Print automatically when the window opens.
// This call will block until the print dialog exits!
printWindow.executeJavaScript("print();");
// Close the window automatically after printing
printWindow.executeJavaScript("self.close();");

I solved exporting Table contents to HTML, with an handcoded algorithm, and creating PDF from HTML using
Flying Saucer
XHTML renderer

Carmelo,

You used this code:

getApplication().getMainWindow().open(new ExternalResource(printWindow.getURL()), "_blank");

But in Vaadin 7 the getURL() method is no longer available for the WIndow element. Dod you know what has replaced it?

Thanks!