TelerikReportViewer in React Redirect When export

3 Answers 34 Views
General Discussions
Arifullah
Top achievements
Rank 1
Iron
Arifullah asked on 09 Jul 2024, 12:41 PM

Hi,

I'm currently using the Telerik Report viewer in React. It works fine when displaying the report, but I encounter an issue when trying to export the report. Upon attempting to export, it redirects me to the following route:

http://localhost:5000/api/reports/clients/32a9a544f84/instances/bf7cdf0ed6c/documents

This route isn't configured in the routing setup, leading to a subsequent redirection to a 404 error page.

 

"@progress/telerik-react-report-viewer": "^19.23.718",

3 Answers, 1 is accepted

Sort by
0
Accepted
Arifullah
Top achievements
Rank 1
Iron
answered on 17 Jul 2024, 06:10 AM | edited on 17 Jul 2024, 06:23 AM

I Have Solved the Issue by Creating the Route That Report viewer redirect and downloading the report


downloadReportAPI: (clientId: string, instanceId: string, documentId: string) =>
    axios.get<any>(
      `/reports/clients/${clientId}/instances/${instanceId}/documents/${documentId}?response-content-disposition=attachment`
    ),


import React, { useEffect, useState } from 'react';
import { useNavigate, useParams, useLocation, Navigate } from 'react-router-dom';
import { observer } from 'mobx-react-lite';
import { useStore } from 'src/stores/store';

export default observer(function DownloadReport() {
  const { clientId, instanceId, documentId } = useParams();
  const { pathname } = useLocation();
  const [loading, setLoading] = useState(false);
  const [text, setText] = useState('....');
  const navigate = useNavigate();
  const {
    ReportStore: { downloadReport, loadingList },
  } = useStore();

  const downloadFile = async (response: any) => {
    setLoading(true);
    setText('Downloading....');
    if (!response || !response.blob) {
      console.error('Invalid response:', response);
      return;
    }

    try {
      const blob = await response.blob();
      const url = window.URL.createObjectURL(blob);
      const a = document.createElement('a');
      a.href = url;
      a.download = documentId!; // Set a more meaningful file name if needed
      document.body.appendChild(a);
      a.click();
      a.remove();
      setLoading(false);
    } catch (err) {
      console.error('Error while processing the response:', err);
    }
  };

  useEffect(() => {
    const res = downloadReport(clientId!, instanceId!, documentId!);
    downloadFile(res);
  }, [downloadReport]);

  //   useEffect(() => {
  //     downloadFile();
  //   }, [clientId, instanceId, documentId]);

  if (loading) return <h1>{text}</h1>;

  return null;
});

 

0
Momchil
Telerik team
answered on 11 Jul 2024, 10:02 AM

Hello Arifullah,

Indeed, the Resolve Document Request is sent when the report viewer attempts to render a report to one of the available rendering formats. However, this request is not used exclusively by the export functionality. The interactive preview of the viewer requests an HTML5 rendering of the report using the same endpoint. Thus, if this endpoint of the service is inaccessible I would not expect the viewer to work at all.

Can you try connecting one of our demo report viewers to your Reporting REST Service (http://localhost:5000/api/reports) and let me know if the issue persists? For example, you can access our HTML5 Report Viewer Integration demo from the following solution.

C:\Program Files (x86)\Progress\Telerik Reporting <YOUR VERSION>\Examples\CSharp\CSharp.ReportExamples.VS2022.sln

If the error is reproducible with a different viewer, the issue is most likely within the service. In this case, I can suggest the following.

Alternatively, if the error occurs only when you use the React Report Viewer, please send a runnable sample I can use to reproduce this locally and I will let you know what I find.

Kind Regards,
Momchil
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
0
Arifullah
Top achievements
Rank 1
Iron
answered on 11 Jul 2024, 10:26 AM

Hi

<TelerikReportViewer ref={(el: any) => (viewer = el)} serviceUrl={url} authenticationToken={token} reportSource={{ report: reportName, parameters: { Parameter1: JSON.stringify(data), Parameter2: reportParams, }, }} viewerContainerStyle={{ position: 'absolute', left: '5px', right: '5px', top: '50px', bottom: '5px', overflow: 'hidden', clear: 'both', fontFamily: 'ms sans serif', }} viewMode="INTERACTIVE" scaleMode="SPECIFIC" scale={1.0} enableAccessibility={false} />


using Telerik.Reporting.Services;
using Telerik.Reporting.Services.AspNetCore;

namespace API.Controllers
{

    [Route("api/reports")]
    [ApiController]
    public class ReportsController : ReportsControllerBase
    {
        public ReportsController(IReportServiceConfiguration reportServiceConfiguration)
       : base(reportServiceConfiguration)
        {
        }

    }
}

I am passing the data to report through Parameter1: JSON.stringify(data)

it's the same in all reports when I click on export to PDF or Excel it redirects to another page 

I want the report viewer not to redirect and download the report

 

 

Momchil
Telerik team
commented on 15 Jul 2024, 07:59 AM

Hi Arifullah,

Thank you for sharing your setup.

The configuration of the viewer and the reports controller looks valid. Still, the routing settings of the application can block some of the endpoints of the Reporting REST Service.

Did you check if connecting the viewer to a different Reporting REST Service resolved the export issue? If you do not have the examples I mentioned, you can also use our public demos API (https://demos.telerik.com/reporting/api/reports) to test. For example, you can make the following changes to your viewer to preview the Dashboard report from our demos.

  <TelerikReportViewer
        serviceUrl="https://demos.telerik.com/reporting/api/reports"
        reportSource={{
          report: "Dashboard.trdx"
        }}
        ...
      />

If you can successfully export the Dashboard report from our demos, we need to test the application that hosts your Reporting REST Service. To do that, please record the trace listener log I mentioned in my previous reply.

Regards,
Momchil

Arifullah
Top achievements
Rank 1
Iron
commented on 15 Jul 2024, 09:43 AM

Now I'm getting the following error
The version of the Report Viewer '17.1.23.718' does not match the version of the Reporting REST Service '18.1.24.514'. Please make sure both are running the same version.

 

Momchil
Telerik team
commented on 16 Jul 2024, 03:03 PM

Hi Arifullah,

Indeed, the versions of the viewer and the service need to match.
Earlier I forgot to mention that our demos use the 18.1.24.514 version. Apologies for the oversight.

If you do not wish to update your viewer to 18.1.24.514, you can run the attached REST Service project instead and point the viewer to it.

  <TelerikReportViewer
        serviceUrl="http://localhost:59655/api/reports"
        reportSource={{
          report: "SampleReport.trdp"
        }}
        ...
      />

 

Arifullah
Top achievements
Rank 1
Iron
commented on 17 Jul 2024, 06:03 AM

Hi

I Run Your Reporting Services Project and Connected my Report viewer From my app. It is ok and there is no redirect to another page 

but here only pass a report name 

<TelerikReportViewer
        serviceUrl="http://localhost:59655/api/reports"
        reportSource={{
          report: "SampleReport.trdp"
        }}
        ...
      />

 

and I pass the data through parameters to report  also

  serviceUrl={url}
          authenticationToken={token}
          reportSource={{
            report: reportName,
            parameters: {
              Parameter1: JSON.stringify(data),
              Parameter2: reportParams,
            },
          }}
maybe passing the data through parameter case this issue?

 

Tags
General Discussions
Asked by
Arifullah
Top achievements
Rank 1
Iron
Answers by
Arifullah
Top achievements
Rank 1
Iron
Momchil
Telerik team
Share this question
or