ActiveReports 9 > ActiveReports User Guide > How To > Customize, Localize, and Deploy > Customize HTML5 Viewer |
ActiveReports HTML5 Viewer is a fully customizable control. You can easily change the look of the viewer and show or hide the components using its public API.
The following example demonstrates few of the many modifications possible in the HTML5 Viewer. It shows setting the Custom uiType, adding the custom buttons for Print and Export and adding the Paginator control that allows you to display the number of report pages and to navigate through them.
Note: These steps assume that you have already created a new ASP.Net Web Application and added a sample report to display in the viewer. |
Note: In ActiveReports, these files are located in the C:\Program Files\GrapeCity\ActiveReports 9\Deployment\Html folder. |
Note: You can obtain the source of Bootstrap.min.js from Content Delivery Network (CDN) like shown in the code below. You can also download the file from the source website and add the file to the project locally. |
Code
Paste inside the <head></head> tags |
Copy Code
|
---|---|
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" /> <link href="/GrapeCity.ActiveReports.Viewer.Html.css" rel="stylesheet" /> |
Code
Paste inside the <body></body> tags |
Copy Code
|
---|---|
<div class="container"> <div id="paginator" class="pagination"></div> <div id="viewer" style="width: auto; height: 600px"></div> </div> |
Code
Paste inside the <body></body> tags |
Copy Code
|
---|---|
<style> #viewer { position: absolute; left: 5px; right: 5px; top: auto; bottom: 5px; font-family: 'segoe ui', 'ms sans serif'; overflow: hidden; } </style> |
Code
Paste inside the <body></body> tags |
Copy Code
|
---|---|
<div class="panel panel-default"> <div class="panel-heading"> <div id="appToolbar" class="btn-toolbar" style="margin-bottom: 10px"> <button type="button" class="btn" id="btnPrint"> Print</button> <button type="button" class="btn" id="btnExport"> Export to PDF</button> </div> </div> </div> |
Note: You can obtain the source of dependencies like jQuery from Content Delivery Network (CDN). You can also download and add them to the project locally. |
Code
Paste inside the <head></head> tags |
Copy Code
|
---|---|
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.js" type="text/javascript"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.0/js/bootstrap.js" type="text/javascript"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/knockout/2.3.0/knockout-debug.js" type="text/javascript"></script> <script src="/GrapeCity.ActiveReports.Viewer.Html.js" type="text/javascript"></script> |
Code
Paste inside the <body></body> tags |
Copy Code
|
---|---|
<script type="text/javascript"> $(function () { var paginator = $('#paginator'); var viewer = GrapeCity.ActiveReports.Viewer( { element: '#viewer', report: { id: "SampleReport.rdlx" }, reportService: { url: '/ActiveReports.ReportService.asmx' }, //Setting the uiType to Custom uiType: 'custom', documentLoaded: function () { setPaginator(); } }); //Creating the function for Printing $('#btnPrint').click(function () { viewer.print(); }); //Creating the function for Exporting $('#btnExport').click(function () { viewer.export('Pdf', function (uri) { window.open(uri); }, false, {}); }); //Creating the function for using Paginator control to display report pages and to navigate through them function setPaginator() { if (viewer.pageCount > 0) { for (var i = 1; i <= viewer.pageCount; i++) { $('<li data-bind="' + i + '"><a class="js-page" href="javascript:void(0)">' + i + '</a></li>').appendTo(paginator); } paginator.children(":first").addClass('active'); paginator.children().click(function () { var self = $(this); viewer.goToPage(self.attr('data-bind'), 0, function () { paginator.children().removeClass('active'); self.addClass('active'); }); }); } } }); </script> |