Skip to main content

WebDocumentViewerClientSideEventsBuilder.BeforeRender(String) Method

Specifies the JavaScript function that handles the client-side BeforeRender event.

Namespace: DevExpress.AspNetCore.Reporting.WebDocumentViewer

Assembly: DevExpress.AspNetCore.Reporting.v23.2.dll

NuGet Package: DevExpress.AspNetCore.Reporting

Declaration

public WebDocumentViewerClientSideEventsBuilder BeforeRender(
    string callback
)

Parameters

Name Type Description
callback String

The name of a JavaScript function or entire JavaScript function code that runs when the BeforeRender event occurs.

Returns

Type Description
WebDocumentViewerClientSideEventsBuilder

WebDocumentViewerClientSideEventsBuilder that can be used for method chaining.

Remarks

Handle the BeforeRender event to customize the Web Document Viewer’s View Model before it is bound to an HTML element and/or before Knockout binding is activated.

The handler function receives two parameters. The first parameter is the object that exposes the IPreviewModel interface (or the JSReportViewer object). The second is the Document Viewer model that allows you to adjust control settings.

The following code snippet sets the zoom level to 25%, enables multi-page mode, and indicates the moment when the first page is loaded:

<div id="loader"> <div id="loaderText"> </div> </div>
<script type="text/javascript" id="script">
    function onBeforeRender(s, e) {
        e.reportPreview.zoom = 0.25;
        e.reportPreview.showMultipagePreview = true;
        $("#loaderText").text("Waiting for the first page..");
        //Get a property that contains the document's page information.
        //Subscribe to property change.
        e.reportPreview.events.on('propertyChanged', (args) => {
            if (args.propertyName === 'pages') {
                const newValue = args.newValue;
                if (newValue.length > 0) {
                    $("#loaderText").text("");
                }
            }
        });
    }
</script>

@{
    var viewerRender = Html.DevExpress().WebDocumentViewer("DocumentViewer")
        .Height("1000px")
        .ClientSideEvents(configure => configure.BeforeRender("onBeforeRender"))
        .Bind("TestReport");
    @viewerRender.RenderHtml()
} 
See Also