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

Is there a way for Telerik Report Viewer Restful service to setup DataSource dynamically at some particular stage.

3 Answers 321 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Viacheslav
Top achievements
Rank 1
Viacheslav asked on 21 Nov 2018, 05:06 PM

We have a few reports implemented to work with old ASP.NET Web Forms. Recently we moved to Angular 5 + Asp.Net Web API.
The distinctive feature of those report is the dynamic design based on the data evaluated as a DataSource for that report. 

The OLD (web forms) implementation follows steps below:
We have several business entities. As a first step we get the data related to those entities:

var reportData = ReportsUtility.GetReportData(reportParameters);

After that we create an Instance Report Source:

var reportSource = ReportsUtility.GetInstanceReportSource(reportData);


GetInstanceReportSource(..)
method implementation detail.
Create a report book:

var reportBook =  new ReportBook();

For each of entities based on data obtained we create specific report instance and transfer the data into it and than attach the report to a report work book:

foreach (var entityData in reportData)
{
    var specificReport = new SpecificReport(entityData);
    reportBook.Reports.Add(specificReport);
}

Return newly created Instance Report Source:

return new InstanceReportSource {ReportDocument = reportBook};

 

Finally we assign the report source to a report viewer control

New back-end (Restful Service) implementation via CustomResolver is the following:

public class CustomReportResolver : IReportResolver
    {
        public ReportSource Resolve(string reportJSON)
        {
            var response = new InstanceReportSource();
            var reportParameters = JsonConvert.DeserializeObject<ReportRequestDto>(reportJSON);
            if (null == reportJSON) return response;

            var reportData = ReportsUtility.GetReportData(reportParameters);
            response = ReportsUtility.GetInstanceReportSource(reportData);

            return response;
        }
    }


Everything works smoothly but as per Angular Telerik Report Viewer client lifecycle there are several calls to a back-end service:
GetParameters, CreateInstance, GetDocument ... and each of them internally invokes CustomResolver.Resolve(...) which causes data for the report evaluated several times.

So my question is there is a standard sensibility point or a simple workaround on how to set up DataSource for the report viewer once or at lease during some specific stage?

3 Answers, 1 is accepted

Sort by
0
Accepted
Todor
Telerik team
answered on 26 Nov 2018, 10:06 AM
Hello Viacheslav,

The Resolve() method of the ReportResolver indeed gets called several times - check Report created multiple times forum post for details.
If you want the data retrieving logic to be executed only once and then the data to be reused by the successive calls, you can use a design pattern (e.g. Singleton), caching, or other approach, as suggested in the above forum thread.

The ReportsController gets instantiated on each request to the Telerik Reporting REST Service. This way it does *not* preserve its state. In the default implementation that we provide with our item template there is a static ReportServiceConfiguration property that receives its value in the static constructor of the ReportsController. The ReportResolver gets instantiated there so that this happens only once.

Regards,
Todor
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
0
Viacheslav
Top achievements
Rank 1
answered on 15 Jan 2019, 03:04 PM
Thanks for the links provided
0
Viacheslav
Top achievements
Rank 1
answered on 15 Jan 2019, 03:04 PM
Thank you
Tags
General Discussions
Asked by
Viacheslav
Top achievements
Rank 1
Answers by
Todor
Telerik team
Viacheslav
Top achievements
Rank 1
Share this question
or