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

4 posts, 1 answers
  1. Viacheslav
    Viacheslav avatar
    3 posts
    Member since:
    Apr 2013

    Posted 21 Nov 2018 Link to this post

    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?

  2. Answer
    Todor
    Admin
    Todor avatar
    298 posts

    Posted 26 Nov 2018 Link to this post

    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
  3. Viacheslav
    Viacheslav avatar
    3 posts
    Member since:
    Apr 2013

    Posted 15 Jan in reply to Todor Link to this post

    Thanks for the links provided
  4. Viacheslav
    Viacheslav avatar
    3 posts
    Member since:
    Apr 2013

    Posted 15 Jan in reply to Todor Link to this post

    Thank you
Back to Top