Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

ListGrid print/pdf-export shows loading message

$
0
0
Hello.

I currently allow printing (Canvas.showPrintPreview) and PDF exporting (RPCManager.exportContent) in our ListGrids.

I use paged fetch mode, because our datasources have thousands of records. But when the user prints (or exports), I fetch all data to be able to correctly print them.

Unfortunately, sometimes I see the loading message in the resulting printing/export. Usually multiple copies of it. I investigated it further and concluded that the HTML generation runs asynchronously (probably for performance reasons) and the problem occurs when the grid is changed/redrawn during this generation (because of a timed refresh or simply because the user used the filter).

Then I tried to block the grid from automatic refreshes and user interaction, but I could not find a way to know when the HTML generation has finished. Tried to override getPrintHTML but it returns null and the callback is never called.

I are using the following code:

Code:

@Override
public String getPrintHTML(PrintProperties printProperties, final PrintHTMLCallback callback) {
        logger.info("getPrintHTML called");
        String html = super.getPrintHTML(printProperties, new PrintHTMLCallback() {
                @Override
                public void setHTML(String html) {
                        logger.info("getPrintHTML before callback");
                        callback.setHTML(html);
                        logger.info("getPrintHTML after callback");
                }
        });
        logger.info("getPrintHTML returned len " + (html == null ? html : html.length()));
        return html;
}

// This method is missing from RPCManager
// http://forums.smartclient.com/showpost.php?p=104184&postcount=2
private static native void exportContent(Canvas[] canvas, DSRequest requestProperties) /*-{
        var canvasJS = @com.smartgwt.client.util.JSOHelper::convertToJavaScriptArray([Ljava/lang/Object;)(canvas);
        var reqProps = requestProperties == null ? null : requestProperties.@com.smartgwt.client.core.DataClass::getJsObj()();
        $wnd.isc.RPCManager.exportContent(canvasJS, reqProps);
}-*/;

private Canvas[] getPrintView() {
        return new Canvas[] { printHeader, this };
}

protected void startExportingPdf() {
        runAfterFullFetch(new Runnable() {
                @Override
                public void run() {
                        DSRequest requestProperties = new DSRequest();
                        requestProperties.setAttribute("skinName", "myskin");
                        requestProperties.setAttribute("pdfName", "report);
                        requestProperties.setExportDisplay(ExportDisplay.DOWNLOAD);
                        exportContent(getPrintView(), requestProperties);
                }
        });
}

protected void startPrinting() {
        runAfterFullFetch(new Runnable() {
                @Override
                public void run() {
                        Canvas.showPrintPreview(getPrintView());
                }
        });
}

private void setResultSetFetchModePostCreate(FetchMode fetchMode) {
        getOriginalResultSet().setAttribute("fetchMode", fetchMode.getValue(), true);
}

private void runAfterFullFetch(final Runnable runnable) {
        dataArrivedRegistration = addDataArrivedHandler(new DataArrivedHandler() {
                @Override
                public void onDataArrived(DataArrivedEvent event) {
                        removeDataArrivedRegistration();
                        runnable.run();
                        pendingPagedMode = true;
                }
        });

        // Set the grid to fetch all records
        setResultSetFetchModePostCreate(FetchMode.BASIC);
        // Force fetch
        invalidateCache();
}

@Override
public void invalidateCache() {
        logger.info("invalidateCache called");
        if (pendingPagedMode) {
                pendingPagedMode = false;
                logger.info("Back to PAGED mode");
                setResultSetFetchModePostCreate(FetchMode.PAGED);
        }
        super.invalidateCache();
}

private void removeDataArrivedRegistration() {
        if (dataArrivedRegistration != null) {
                dataArrivedRegistration.removeHandler();
        }
        dataArrivedRegistration = null;
}


Viewing all articles
Browse latest Browse all 4756

Trending Articles