How to customize in JavaScript ReportViewer?
This article describes how to customize the standard toolbar in JavaScript ReportViewer. The toolbar customization is the process of changing standard functionalities to meet the requirement.
Refer to the Getting Started with JavaScript ReportViewer from the existing User Guide that is available in the following link.
Toolbar Customization in JavaScript Reportviewer
Syncfusion JavaScript ReportViewer supports the Toolbar Customization. By using toolbarSettings property, you can customize the toolbar of ReportViewer either with the template customization or without the template customization.
Toolbar Customization
You can show or hide the toolbar items of ReportViewer as per the requirement by using toolbarSettings property. To customize the toolbar, set the items for the toolbarSettings property as in the following code example.
JS
<script type="text/javascript"> $("#container").ejReportViewer( { reportServiceUrl: '/api/ReportApi', processingMode: ej.ReportViewer.ProcessingMode.Local, reportPath: '~/App_Data/Product Catalog.rdlc', toolbarSettings: { items: ej.ReportViewer.ToolbarItems.All & ~ej.ReportViewer.ToolbarItems.Print & ~ej.ReportViewer.ToolbarItems.FittoPage & ~ej.ReportViewer.ToolbarItems.Refresh & ~ej.ReportViewer.ToolbarItems.PrintLayout} }) </script>
Run the Application
Run the sample application to render the customized toolbar of JavaScript ReportViewer as displayed in the following screenshot.
Figure 1: Toolbar customization without template
Demo Sample
You can download the Demo Sample from the following link.
Toolbar Template Customization
Toolbar Template customization helps you to customize the toolbar UI instead of standard toolbar. By using the templateId property of ReportViewer, you can hide the standard toolbar and replace the new toolbar. The following code example explains how to customize toolbar by using the template.
HTML
<div id="toolbarTemplate"> <ul> <li id="_Print"> <div class="ctrlbutton"> <span class="printpage" style="display:block;"></span> </div> </li> </ul> <ul> <li id="_Gotofirst"> <div class="ctrlgotofirst"> <span class="gotofirstpage" style="display:block;"></span> </div> </li> <li id="_GotoPrevious"> <div class="Previous"> <span class="gotopreviouspage" style="display:block;"></span> </div> </li> <li id="_GotoPageNo"> <div class="ctrlltextbox"> <input type="text" id="_textBox1" onkeyup="GotopageNo()" value="1"/> </div> </li> <li id="_GotoNext"> <div class="Next" style="width:20px;height:20px;"> <span class="gotonextpage" style="display:block;"></span> </div> </li> <li id="_GotoLast"> <div class="ctrlgotoLast"> <span class="gotolastpage" style="display:block;"></span> </div> </li> </ul> <ul> <li id="_Dropdown" title="Dropdown for export list"> <button id="select"> <ul> <li> <span class="export" style="display:block;"> Export</span> </li> </ul> </button> <ul id="exportlist"> <li id="PDF"> <span class="pdfexport" style="display:block;">Pdf</span> </li> <li id="Word"> <span class="wordexport" style="display:block;">Word</span> </li> <li id="Excel"> <span class="excelexport" style="display:block;">Excel</span> </li> </ul> </li> </ul> <ul> <li id="_zoomin"> <div class="ctrlzoomin"> <span class="zoominpage" style="display:block;"></span> </div> </li> <li id="_zoomout"> <div class="ctrlzoomout"> <span class="zoomoutpage" style="display:block;"></span> </div> </li> </ul> <ul> <li id="_FitToPage"> <div class="ctrlfittopage"> <input type="checkbox" id="fittopage" style="display:block"/> </div> </li> <li id="_Refresh"> <div class="ctrlreferesh"> <span class="refereshpage" style="display:block;"></span> </div> </li> </ul> </div> <div id="container" style="height:560px; width: 1025px; margin-left: 200px;"></div>
Add the following CSS code example inside the <style> tag of the default html page.
CSS
<style> .printpage { background: url('Content/Icons/Print.png'); width: 25px; height: 25px; background-position: center; background-repeat: no-repeat; } .gotofirstpage { background: url('Content/Icons/Gotofirst.png'); width: 25px; height: 25px; background-position: center; background-repeat: no-repeat; } .gotopreviouspage { background: url('Content/Icons/Previous.png'); width: 25px; height: 25px; background-position: center; background-repeat: no-repeat; } .gotonextpage { background: url('Content/Icons/Next.png'); width: 25px; height: 25px; background-position: center; background-repeat: no-repeat; } .gotolastpage { background: url('Content/Icons/Gotolast.png'); width: 25px; height: 25px; background-position: center; background-repeat: no-repeat; } .export { background: url('Content/Icons/Export.png'); width: 25px; height: 25px; background-position: top; background-repeat: no-repeat; } .pdfexport { background: url('Content/Icons/Pdf.png'); width: 25px; height: 25px; background-position: left; background-repeat: no-repeat; } .wordexport { background: url('Content/Icons/Word.png'); width: 25px; height: 25px; background-position: left; background-repeat: no-repeat; } .excelexport { background: url('Content/Icons/Excel.png'); width: 25px; height: 25px; background-position: left; background-repeat: no-repeat; } .zoominpage { background: url('Content/Icons/Zoomin.png'); width: 25px; height: 25px; background-position: center; background-repeat: no-repeat; } .zoomoutpage { background: url('Content/Icons/Zoomout.png'); width: 25px; height: 25px; background-position: center; background-repeat: no-repeat; } .Fittopage { background: url('Content/Icons/FittoPage.png'); width: 25px; height: 25px; background-position: top; background-repeat: no-repeat; } .refereshpage { background: url('Content/Icons/Refresh.png'); width: 25px; height: 25px; background-position: center; background-repeat: no-repeat; } #toolbarTemplate div { display: inline-block; } #toolbarTemplate div ul li { display: inline-block; } #toolbarTemplate { height: 40px; padding-top: 5px; } #_textBox1 { width: 30px; text-align: center; } </style>
Add the following code example inside the <script> tag of the Default.html page. Also set the desired ReportPath and ReportServiceUrl to ReportViewer.
JS
<script type="text/javascript"> $("#container").ejReportViewer( { reportServiceUrl: '/api/ReportApi', processingMode: ej.ReportViewer.ProcessingMode.Local, reportPath: '~/App_Data/Master-Details.rdlc', toolbarSettings: { templateId: "toolbarTemplate", click: OnToolbarClick } }) $("#fittopage").ejToggleButton({ size: "normal", showRoundedCorner: true, contentType: "imageonly", defaultPrefixIcon: "Fittopage", height:"25px", click:"fitopage", change: "fitopagechange", }); $('#select').ejSplitButton({ height: "25px", width: "60px", targetID: "exportlist", contentType: "imageonly", prefixIcon: "export", itemSelected: "Itemclick" }); var reportObject = $("#container").data("ejReportViewer"); function OnToolbarClick(args) { var currentTarget = args.currentTarget.id; var zoomvalue = reportObject.model.zoomFactor; switch (currentTarget) { case "_Print": { reportObject.print(); break; } case "_Gotofirst": { reportObject.gotoFirstPage(); document.getElementById('_textBox1').value = reportObject._currentPage; break; } case "_GotoPrevious": { reportObject.gotoPreviousPage(); document.getElementById('_textBox1').value = reportObject._currentPage; break; } case "_GotoNext": { reportObject.gotoNextPage(); document.getElementById('_textBox1').value = reportObject._currentPage; break; } case "_GotoLast": { reportObject.gotoLastPage(); document.getElementById('_textBox1').value = reportObject._currentPage; break; } case "_zoomin": { if (zoomvalue >= 6) { reportObject.setModel({ 'zoomFactor': 6 }); } else if (zoomvalue <= 0.5) { reportObject.setModel({ 'zoomFactor': 0.75 }); } else { reportObject.setModel({ 'zoomFactor': ++zoomvalue - 0.75 }); } break; } case "_zoomout": { if (zoomvalue <= 0.75) { reportObject.setModel({ 'zoomFactor': 0.5 }); } else if (zoomvalue <= 1) { reportObject.setModel({ 'zoomFactor': 0.75 }); } else { reportObject.setModel({ 'zoomFactor': --zoomvalue + 0.75 }); } break; } case "_Refresh": { reportObject.refresh(); document.getElementById('textBox').value = reportObject._currentPage; reportObject.setModel({ 'zoomFactor': 1 }); break; } } } function GotopageNo() { var currenttext=parseInt(document.getElementById('_textBox1').value); if (currenttext != null) { var temp = reportObject._pageModel.TotalPages; if (currenttext <= temp) { reportObject.gotoPageIndex(currenttext); } } } function fitopage(args) { if(args.isChecked == true) { reportObject.fitToPage(); } else { reportObject._resetPage(); } } function Itemclick(args) { var currentTarget = args.ID; switch (currentTarget) { case "Word": reportObject.exportReport("Word_Word2010"); break case "Excel": reportObject.exportReport("Excel_Excel2010"); break case "PDF": case "Html": reportObject.exportReport(currentTarget); break } } </script>
Figure 2: Toolbar Template Customization
Demo Sample
You can download the Demo Sample from the following link.
https://www.syncfusion.com/downloads/support/directtrac/general/ToolbarCustomization852482359.zip
Further References
You can find the online User Guide Documentation and the online Demo Samples for the JavaScript ReportViewer control from the following link.