This is a migrated thread and some comments may be shown as answers.

Accessing reportDocument in MVC jsscripts

1 Answer 27 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Amit asked on 07 Jun 2017, 02:09 PM
     // Each report viewer must have an id - it will be used by the initialization script
     // to find the element and initialize the report viewer.
     // The URL of the service which will serve reports.
     // The URL corresponds to the name of the controller class (ReportsController).
     // For more information on how to configure the service please check
     // The URL for custom report viewer template. The template can be edited -
     // new functionalities can be added and unneeded ones can be removed.
     // .TemplateUrl(Url.Content("~/ReportViewer/templates/telerikReportViewerTemplate-"))
     // Strongly typed ReportSource - TypeReportSource or UriReportSource.
     .ReportSource(new TypeReportSource() { TypeName = "WebApplication2.Report.Report1, WebApplication2, Version=, Culture=neutral, PublicKeyToken=null" })
     // Specifies whether the viewer is in interactive or print preview mode.
     // PrintPreview - Displays the paginated report as if it is printed on paper. Interactivity is not enabled.
     // Interactive - Displays the report in its original width and height with no paging. Additionally interactivity is enabled.
     // Sets the scale mode of the viewer.
     // Three modes exist currently:
     // FitPage - The whole report will fit on the page (will zoom in or out), regardless of its width and height.
     // FitPageWidth - The report will be zoomed in or out so that the width of the screen and the width of the report match.
     // Specific - Uses the scale to zoom in and out the report.
     // Zoom in and out the report using the scale
     // 1.0 is equal to 100%, i.e. the original size of the report
     // Sets whether the viewer’s client session to be persisted between the page’s refreshes(ex. postback).
     // The session is stored in the browser’s sessionStorage and is available for the duration of the page session.
     // Sets the print mode of the viewer.
             events => events




using above code to host report in .cshtml 

I need to access client side api in javascript. 

var viewer = <%=ReportViewer1.ClientID%> // Not able to access reportViewer object in .cshtml

  <script type="text/javascript">
        function PrintRepo() {
           PrintDocument(); //if I get the access of reportViewer, then I can use PrintDocument() function

Any help is appreciated. Thanks 


1 Answer, 1 is accepted

Sort by
Telerik team
answered on 08 Jun 2017, 10:39 AM
Hi Amit,

To access the viewer's object you can use the following code:
var reportViewer = $("#reportViewer1").data("telerik_ReportViewer");

To print the report, you can use viewer's print command:
$('#printButton').click(function () {
    var rv = $("#reportViewer1").data("telerik_ReportViewer");

Another approach is to add HTML element to the page that has the viewer's data attributes responsible for printing:
<button id="printButton" data-command="telerik_ReportViewer_print" data-target-report-viewer="#reportViewer1">Print report</button>

Hope this will help.

Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
General Discussions
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question