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

Dynamic Data to Report

5 Answers 613 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Aubrey Ivan
Top achievements
Rank 1
Aubrey Ivan asked on 30 Oct 2019, 07:33 AM
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?

5 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 01 Nov 2019, 04:15 PM

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
0
Aubrey Ivan
Top achievements
Rank 1
answered on 02 Nov 2019, 02:16 AM

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?

0
Aubrey Ivan
Top achievements
Rank 1
answered on 02 Nov 2019, 02:19 AM
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
0
Todor
Telerik team
answered on 06 Nov 2019, 12:37 PM

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
0
Aubrey Ivan
Top achievements
Rank 1
answered on 07 Nov 2019, 12:44 AM

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

Tags
General Discussions
Asked by
Aubrey Ivan
Top achievements
Rank 1
Answers by
Todor
Telerik team
Aubrey Ivan
Top achievements
Rank 1
Share this question
or