Skip to main content
A newer version of this page is available. .

WebDocumentViewerClientSideEventsBuilder.BeforeRender(String) Method

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

Namespace: DevExpress.AspNetCore.Reporting.WebDocumentViewer

Assembly: DevExpress.AspNetCore.Reporting.v21.1.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 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 the control’s 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..");
    $("#loader").dialog({ title: "Document Viewer", hide: { delay: 1000 } });
    //Get a property that contains the document's page information. 
    var pages = e.reportPreview.pages;
    //Subscribe to property change. 
    var pagesSubscription = pages.subscribe(function (newValue) {
        if (newValue.length > 0) {
            $("#loader").dialog("close");
            //Stop tracking changes.
            pagesSubscription.dispose();
        }
    });}
</script>

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