You can customize the WebViewer interface using JQuery methods. WebViewer control adds JQuery library in page scripts. Use the code in this walkthrough to add a button on the toolbar and add a client side PDF export implementation.
When you complete this walkthrough you get a WebViewer that looks similar to the following at run time.
In the Source view of the WebForm.aspx file, add the following code.
Add this code after the <head> tag |
Copy Code
|
---|---|
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> |
The HTML WebViewer is created using the MVVM pattern that provides a view model which does not depend on the UI. The code can access the Viewer's view model and bind the custom UI to it by using well-documented properties and methods. For MVVM support, the code can use knockout.js which is the standard MVVM library for JavaScript. Knockout.js provides declarative bindings, observable objects and collections in HTML markup.
Follow the steps below to access the ViewModel.
Paste the code into .aspx source |
Copy Code
|
---|---|
<script> function viewer_loaded() { }; function document_onload() { }; </script> ... <body onload="document_onload()"> |
Paste the code into .aspx source |
Copy Code
|
---|---|
function viewer_loaded() { var viewModel = GetWebViewer('ArWebViewerDiv_WebViewer1'); }; |
Paste the code into .aspx source |
Copy Code
|
---|---|
function document_onload() { $('#WebViewer1').ready(viewer_loaded); }; |
In the Source view of the WebForms.aspx file, add the following Javascript code inside the viewer_loaded event handler to access the WebViewer toolbar. Lets add the custom button in the toolbar - an export button and add PDF export functionality to it.
Paste the code into .aspx source |
Copy Code
|
---|---|
function viewer_loaded() { var viewModel = GetWebViewer('ArWebViewerDiv_WebViewer1'); var pdfExportButton = { key: '$pdfExportButtonKey', text: 'To PDF', iconCssClass: 'mdi mdi-file-pdf', enabled: true, action: function (item) { console.log('Export to PDF function works here'); }, onUpdate: function (arg, item) { console.log(The Viewer UI was updated, check/update button state here'); } }; viewModel.toolbar.desktop.addItem(pdfExportButton); }; |
The complete code for WebForm1.aspx in the Source view is as shown:
Paste the code into .aspx source |
Copy Code
|
---|---|
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %> <%@ Register assembly="MESCIUS.ActiveReports.Web" namespace="GrapeCity.ActiveReports.Web" tagprefix="ActiveReportsWeb" %> <!DOCTYPE html> <html xmlns="https://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body onload="document_onload()"> <form id="form1" runat="server"> <div> <ActiveReportsWeb:WebViewer ID="WebViewer1" runat="server" height="466px" width="667px" ReportName="AllCustomers.rdlx"> </ActiveReportsWeb:WebViewer> </div> </form> <script src="https://code.jquery.com/jquery-2.1.4.min.js"> </script> <script> function viewer_loaded() { var viewModel = GetWebViewer('ArWebViewerDiv_WebViewer1'); var pdfExportButton = { key: '$pdfExportButtonKey', text: 'To PDF', iconCssClass: 'mdi mdi-file-pdf', enabled: true, action: function (item) { console.log('Export to PDF function works here'); }, onUpdate: function (arg, item) { console.log('Something in viewer was updated, check/update button state here'); } }; viewModel.toolbar.desktop.addItem(pdfExportButton); }; function document_onload() { $('#WebViewer1').ready(viewer_loaded); }; </script> </body> </html> |
Paste the code into .aspx source |
Copy Code
|
---|---|
function viewer_loaded() { var viewModel = GetWebViewer('ArWebViewerDiv_WebViewer1'); ... viewModel.toolbar.desktop.removeItem($newButtonKey); //(key of the button) }; |
Note: