ActiveReports 9 > ActiveReports User Guide > Samples and Walkthroughs > Walkthroughs > Common Walkthroughs > Professional > Customizing the HTML Viewer UI |
You can customize the HTMLViewer interface using JQuery methods. WebViewer control adds JQuery library in page scripts. Use the code in this walkthrough to remove a button from the HTMLViewer toolbar and add a client side PDF export implementation.
This walkthrough is split into the following activities:
When you complete this walkthrough you get an HTMLViewer that looks similar to the following at runtime.
To load an ActiveReport in the Web application
Note: You may load any report, section or page in the HTMLViewer. See Getting Started with the Web Viewer for information on loading a report. |
To access the WebViewer view model
The HTML Web Viewer 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. See Working with HTML Viewer using Javascript for more information.
Follow the steps below to access the ViewModel.
Add a script tag like the following before the body tag |
Copy Code
|
---|---|
<script language="javascript" type="text/javascript"> </script> |
Paste the code into .aspx source |
Copy Code
|
---|---|
<script language="javascript" type="text/javascript"> |
Paste the code into .aspx source |
Copy Code
|
---|---|
var viewModel = GetViewModel('WebViewer1'); |
Paste the code into .aspx source |
Copy Code
|
---|---|
$('#WebViewer1').bind('loaded', viewer_loaded); |
To remove a button from the WebViewer toolbar
In the Source view of the Default.aspx file, add the following Javascript code inside the viewer_loaded event handler to access the WebViewer toolbar and remove the Next Page button from the toolbar:
Paste the code into .aspx source |
Copy Code
|
---|---|
var toolbar = $('#WebViewer1').find('.arvToolBar'); |
Note: In order to access the child elements of the WebViewer toolbar you need their css class names. Following is a list for reference: Toolbar Child Elements
Toggle Sidebar button: btnToggleSidebar
Find button: btnFind First page button: btnFirst Previous page button: btnPrev Page label: toolbarLabel Page number input box: toolbarInput Next page button: btnNext Last page button: btnLast Back to parent report button: btnBack |
To add a function for exporting to PDF
The steps below illustrate how to build a custom UI.
Paste the code into .aspx source |
Copy Code
|
---|---|
function exportPDF() var viewModel = GetViewModel('WebViewer1'); if (viewModel.PageLoaded()) |
Paste the code into .aspx source |
Copy Code
|
---|---|
<div id="customToolbar" style = "display:inline"> |
Paste the code into .aspx source |
Copy Code
|
---|---|
$('#customToolbar').appendTo(toolbar); |
To bind the custom UI to the WebViewer view model and run the application
Paste the code into .aspx source |
Copy Code
|
---|---|
ko.applyBindings(viewModel, document.getElementById("customToolbar")); |
Note: Replace 'WebViewer1' in the code snippets above, with the actual ID of the WebViewer control in your application. |