Dynamic Data to Report

6 posts, 0 answers
  1. Aubrey Ivan
    Aubrey Ivan avatar
    25 posts
    Member since:
    Oct 2019

    Posted 30 Oct Link to this post

    Is it possible to generate data on a button clicked and put that data inside a report which has a pre-defined design? I am using asp.net mvc, any guides or demo I could use?
  2. Todor
    Admin
    Todor avatar
    397 posts

    Posted 01 Nov Link to this post

    Hi Aubrey Ivan,

    Our Html5-based Viewers, including the MVC Viewer, use REST Service to deliver reports - check HTML5 Report Viewer and Reporting REST services. All that is related to processing and rendering the report happens in the REST Service, where the reporting engine runs. If you would like to pass the data to the report from the client, it will be necessary to pass it either directly to the report definition, or to the REST Service, where to instantiate the report and assign it data.

    For the first approach that we recommend, you may expose the data in Web service and use the WebServiceDataSource to get it directly from the report.
    Alternatively, you may place the data in a temporary repository from the viewer action, and then get it in the Report. For example, save it in CSV text file and use CsvDataSource.

    In the approach with instantiating the report, you need to use Custom Report Resolver in the REST Service. You may pass the necessary data in the 'report' argument of the Resolve method. You should serialize the data and send it as part of the ReportSource->Report property of the viewer, which will be received as the string 'report'.

    I have attached a sample MVC project demonstrating the approach. I have hard-coded some data in the Home Controller for simplicity as getting the data from a View is not related to the Reporting tool.

    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. Aubrey Ivan
    Aubrey Ivan avatar
    25 posts
    Member since:
    Oct 2019

    Posted 01 Nov in reply to Todor Link to this post

    Hi Todor, 

    Your example helped me out a lot, I just have one more question, what if my data is dynamic and I do not know which type of object I am expecting, how do I handle that inside the custom resolver? Do I create a multiple custom-resolver? or do I make a if-else case statements inside the custom resolver and DeserializeObject the data depending on the if-else statements inside the custom resolver


    I have multiple classes which would be my data, should I use only 1 custom resolver and determine which object it would be deserealized from, inside the customResolver?

  4. Aubrey Ivan
    Aubrey Ivan avatar
    25 posts
    Member since:
    Oct 2019

    Posted 01 Nov in reply to Todor Link to this post

    Hi Todor, 

    If possible I want to re-use the report-viewer by passing a string reportSource to it and handle the data inside the custom resolver, and I also want to re-use the custom-resolver. I would like to deserialize multiple classes inside the custom resolver, how do I do that?


    Regards,
    Ivan
  5. Todor
    Admin
    Todor avatar
    397 posts

    Posted 06 Nov Link to this post

    Hi Ivan,

    It is better if you deserialize the data conditionally, inside a single Custom Report Resolver. For example, you may concatenate a key indicating which data model should be used for deserializing in the report string and use if-else or switch-case statements to control the workflow.

    Note that you have other options to transfer the data to the report, e.g. WebServiceDataSource that gets the data from a custom Web Service.

    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
  6. Aubrey Ivan
    Aubrey Ivan avatar
    25 posts
    Member since:
    Oct 2019

    Posted 06 Nov in reply to Todor Link to this post

    Hi Todor,

    Yes, tha'ts what I intend to do. I will pass the report and data as string and deserialize the data into object depending on the report that was also passed.

    Thanks,
    Ivan

Back to Top