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

Creating report definition file programmatically and then display into HTML5 page

5 Answers 381 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sagar
Top achievements
Rank 1
Sagar asked on 10 Feb 2016, 05:57 AM

Hi,

I want to achieve functionality of creating report definition file (trdx) programmatically and then display into HTML5 page.

For this, I was going through below links-
http://docs.telerik.com/reporting/programmatic-creating-report

http://docs.telerik.com/reporting/report-sources-viewers

However, I couldn't achieve require functionality.

Could you please share step by step guide to achieve this functionality?

5 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 11 Feb 2016, 03:13 PM
Hi Sagar,

In general, the HTML5 Viewer sends a description of the report which has to be processed and rendered on the server. The Reporting REST service handles the requests, resolves the report and returns the rendered content to the client.

If reports are created in Visual Studio or are available as TRDX files on the server, the viewer can request them directly by type's assembly qualified name or path to a TRDX file. If reports has to be customized at run-time (or created) you will need a custom report resolver for Reporting REST service.
For more details, please check the following help article:
http://docs.telerik.com/reporting/report-sources-viewers#for-report-viewers-operating-via-telerik-reporting-services  (HTML5 Viewer).


Please elaborate on the reason to create the report at run-time instead of using a ready report template bound to data.

Regards,
Stef
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
Sagar
Top achievements
Rank 1
answered on 15 Feb 2016, 05:54 AM

Hi Stef,

Thanks for your reply.

As mentioned in link (http://docs.telerik.com/reporting/report-sources-viewers#for-report-viewers-operating-via-telerik-reporting-services), The reportSource.report part is a string that can be a path to a TRDX file, an assembly qualified name of a report class.

 

When I use TRDX file, it works fine. However, when I use qualified name of a report class, it says - "Error creating report instance (Report = Telerik.Reporting.Report2).Report 'Telerik.Reporting.Report2' cannot be resolved."

 

Report2.cs is created using "Telerik Report Q1 2006 (Blank)" template.

 

Below is my Reports Controller code -

public class ReportsController : ReportsControllerBase
    {
        string selectCommand = @"SELECT * FROM AUDIT";
        string connectionString = "<connstring deleted>";

        static Telerik.Reporting.Services.ReportServiceConfiguration configurationInstance =
        new Telerik.Reporting.Services.ReportServiceConfiguration
        {
            HostAppId = "Application1",

            
            ReportResolver = new ReportFileResolver(HttpContext.Current.Server.MapPath("~/Reports"))
                .AddFallbackResolver(new ReportTypeResolver()),
            Storage = new Telerik.Reporting.Cache.File.FileStorage(),


        };

        

        public ReportsController()
        {
            this.ReportServiceConfiguration = configurationInstance;

            Report2 report = new Report2();
            Telerik.Reporting.SqlDataSource sqlDataSource = new Telerik.Reporting.SqlDataSource(connectionString, selectCommand);
            report.DataSource = sqlDataSource;


        }
    }

 

Below is my HTML page code-

   <div id="reportViewer1" class="k-widget">
        loading...
    </div>

    <script type="text/javascript">
        $("#reportViewer1")
            .telerik_ReportViewer({
                serviceUrl: "api/Reports",
                reportSource: {
                    //report: "Report2.trdx",
                    report: "Telerik.Reporting.Report2",

                    parameters: {
                        CultureID: "en"
                    }
                }
            });
    </script>

 

Please suggest, if I am missing anything here.

 

0
Stef
Telerik team
answered on 15 Feb 2016, 02:14 PM
Hello Sagar,

Test to create a report named Report2 in a ClassLibrary project in Visual Studio - How To: Create a Report (Visual Studio). Then add a reference to that ClassLibrary in the project with the viewer.
The viewer's ReportSource.Report can be set to the assembly qualified name of the report class e.g. <namespace>.<report_name>, <assembly_name>.

On the server, the Reporting REST service will use System.Reflection to create an instance of the report by using its default constructor.


If you need to modify data items' DataSource properties e.g. change connection string or the SQL query, you will need a custom resolver for the Reporting REST service. In the custom resolver's Resolve method you can include the logic for getting a report and modifying it. Please consider the example in my post in Changing a parameter's datasource connection string at runtime.

Note that there are approaches to map SQL parameters to report parameters - Using Parameters with the SqlDataSource component. Also connection strings can be saved by name, and thus they will be loaded from the application's configuration file.


We will appreciate it if you elaborate on the reason to modify the report at run-time.

Regards,
Stef
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
Sagar
Top achievements
Rank 1
answered on 17 Feb 2016, 05:20 AM

Hi Stef

Basically we want user to select report to view and section/fields it should contain.

Consider this scenario-
In a HTML5 page, you have a drop down which contains 4 reports.
user selects one of report and corresponding section /fields to be appear on report.
click on button to load that report.
On button click, we should hit WebApi Controller to process report trdx file and reload telerik_ReportViewer with latest trdx file.
Is this possible to achieve? If yes, please suggest some steps to begin with.

 

0
Stef
Telerik team
answered on 19 Feb 2016, 02:58 PM
Hi Sagar,

You can design reports in such manner that report parameters determine the visibility of sections and items via conditional formatting, or/and parameters are used to filter the data.
Then you can use custom UI to let the user select the report (e.g. path to TRDX file) and which sections will be visible and what data will be filtered in (report parameters' values).

With such settings, you can use the default implementation of the Reporting RESt service added through the VS item template. The gathered information can be passed to an HTML5 Viewer (on creating it or later) through its reportSource. Please consider the example in How To: Pass Values to Report Parameters.


In case you need to modify the TRDX file, replace the default resolver of the added Reporting REST service (in the ReportsControllerBase.cs file) and use a custom one - REST Service Report Resolver. The custom resolver's Resolve method will receive as argument the viewer's reportSource.report string and you will be able to handle it in code and return a report source of choice.


I hope this information helps.

Regards,
Stef
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
Tags
General Discussions
Asked by
Sagar
Top achievements
Rank 1
Answers by
Stef
Telerik team
Sagar
Top achievements
Rank 1
Share this question
or