)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Syncfusion Feedback

How to customize the ReportViewer Toolbar?

Platform: jQuery |
Control: ejReportViewer |
Published Date: May 12, 2015 |
Last Revised Date: May 23, 2019

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.

http://help.syncfusion.com/ug/js/documents/createyourfirstrepor.htm

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.

 

C:\Users\sundaraj\Desktop\Snap1.PNG

Figure 1: Toolbar customization without template

Demo Sample

You can download the Demo Sample from the following link.

http://www.syncfusion.com/downloads/support/directtrac/general/ToolbarCustomizewithouttemplate-1548070730.zip

 

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>

 

C:\Users\sundaraj\Desktop\Snap3.PNG

Figure 2: Toolbar Template Customization

Demo Sample

You can download the Demo Sample from the following link.

http://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.

http://js.syncfusion.com/demos/web/ReportViewer

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon