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

Need support for reports modified in code

3 Answers 56 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Thys
Top achievements
Rank 1
Thys asked on 05 Sep 2014, 07:17 AM
Currently reports work fine if everything is designed in the designer or if the full report is generated using code. However, we use design time reports which are extended at run time based on certain parameters. Two very basic use cases for this are:
1) Adding dynamic columns to a table
2) Adding a standard fixed header / footer to the report (with contents depending on the specific report instance)

The issue we have is that the report items we need to add to the report (header or extra columns) depend on data from the database.

It is possible (with a lot of restrictions and workarounds) to get the above working, but it would really make it a lot simpler if the following were available on the report class:
a) An event  / virtual method which can be overridden in a base class which gets called after the design time definition of the report has been created (similar to form loaded in other applications).
b) A way to get access at runtime to the column definitions of the SqlDataSource linked to a table (if it is a Sql source).

Our current partial solution is to set the data source of the table at design time and design the table accordingly. In our report's constructor we clear the data source of the table. In the "need data source" event of the table we create a new data source in code (duplicating the parameters etc. which were already defined during the design), open the dataset, inspect the column list and add the table columns as required. (Actually we return two result sets, one of which is a list of columns to add as selected by the user).



3 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 09 Sep 2014, 01:32 PM
Hello Thys,

The recommended approach is to programmatically retrieve the data which will be sent to the report and get the needed information on how you are going to modify the report. Then, before the report is displayed in the report viewer, modify the report definition in your application. Check the Programmatic Control of Reports help article for further info.

Telerik Reporting provides different declarative means that replace the need for events and provide the needed flexibility to handle most tasks: Using Expressions, Conditional Formatting, Bindings and User Functions. These tools are typically the most productive way to build declarative reports and should be favored over using events. Additionally events can't be used with XML (trdx) report definitions on which the Standalone Report Designer depends. For more information on events, please refer to the Report Events help articles.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Thys
Top achievements
Rank 1
answered on 10 Sep 2014, 08:14 AM
I understand that is the recommended approach. However, it does not work for the case where:
1. A large number of possible columns can be optionally displayed
2. It is only known at runtime (based on the database query with the specific parameters) which columns are to be shown and what their headers are

For reference we are currently using MSSQL Report Services. We achieve this in MSSQL RS by defining 50 generic columns where the headers are retrieved from the database and the column visibility is determined by an expression which also looks at values returned from the database. This type of solutions is ugly and inflexible.

Our initial testing indicates that with Telerik reports (using design time report + run time extension using code) this is much much easier and simpler to achieve. As a test we have converted a few of our reports to Telerik reports and it works quite well.

However, the stumbling blocks we are facing at the moment is that drill through does not work since there is no way when the user navigates back to the report to get the original data again (because the data is cached).

We cannot modify the report in the report constructor since at that point we do not have the run time values of the report parameters available. The possible solutions we see at this point are:
a. Disable data cacheing, forcing the report to render as it did the first time. Is there any way to do this?; or
b. Have an event on the report which is called after the report is created, but with access to the run time parameter values.
0
Stef
Telerik team
answered on 15 Sep 2014, 09:58 AM
Hi Thys,

Telerik reports use cache to avoid the reports' reprocessing and to preserve the state of the content. Thus on navigating back to the initial report trough the viewer's navigation options will display the report with its initial data and in its last saved state. For example check the dill-through action in the Product Sales Per Period online demo.

If the above behavior is not the same at your side, most probably it is due to the used events and code in them. In general, it is not recommended to modify the report's template once the processing with data has started. Using events includes additional settings especially in Web Forms applications depending on Session -  Design Considerations for Out-proc Session State.
The recommended approach for the described scenario is to generate the Table item dynamically at run-time. For example:
var data = GetData();
var report=new MyReport();
 
//generate the Table item template from scratch
Telerik.Reporting.Table table = BuildTableTemplateBasedOnData_AndSetItsDataSource(data);
 
//add the created Table item to the report.Items collection
  (report.Items.Find("detail",true)[0]).Items.Add(table);
 
reportViewer1.ReportSource = new InstanceReportSource {ReportDocument = report};

To build the Table item from scratch you can use and adjust the already generated code in the report's Designer.cs(vb) file. Any complex structures can be created with test data and the VS Report Designer to get the proper generating code for the item.


If you need further help, feel free to open a support ticket and send us demo report, including test data, and details about the experienced issues.

Regards,
Stef
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
Thys
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Thys
Top achievements
Rank 1
Stef
Telerik team
Share this question
or