Example: Nested tables
Docentric Toolkit Help
In this report, we want to write a list of orders with some order details (e.g. shipping address, shipping fee, date of the order etc.) including the complete list of products shipped with this order. We want to arrange these data in a form of nested Word tables. Data model used for all examples is exposed here.
First, build the report template exactly to the stage as it is shown in the example Templating tables.
Now add a Docentric List element from the Docentric Ribbon tab
(about inserting List elements you can read here) to the template in
a way that the whole row of the Word table is comprised.
Set the Value property of the inserted List element by clicking on the Binding Control:
Set its property Binding
Source to the Current Data Context and its Path property to
the property OrderDetails, a collection of type
On the Binding Control's pop-up, select the Data Context (which represents a type Order
- a type of an item of the collection of orders that the parent List element is bound to) as a (Binding) Source and
set the (Binding) Path property to the collection of items of type OrderDetails:
Afterwards add Docentric Field elements to the template withing just inserted List element,
for each order bound to its order details. These Field elements are going to be bound
to some properties of the single order detail, i.e., more precisely, to some properties of the
The Binding Source property of their Value property should be set to Current Data Context,
followed by correctly settings of the Binding Path property.
For example, set the Binding Path property of the following Field element to the property Product.Name:
The result is following:
Finally, the templated table looks like:
We have also defined Format String of the Field element bound to the Product.Price as currency. About formatting values you can read here.
Once again, the finished template (with Desing Mode switched on) looks like:
Next, save the template and generate the report. Report generation takes place programmatically, from your application that is using (has a reference to) the Docentric Report Engine dll. This code looks like following:
// Instancing report engine, by assigning the data source
List<Order> ordersDataSource = DataAccess.GetOrders();
DocumentGenerator dg = new DocumentGenerator(ordersDataSource);
// Generating report by specifying the report template and the resulting report (as file paths)
DocumentGenerationResult result = dg.GenerateDocument("example5.docx", "example5_output.docx");
// Examining potentially errors
foreach (Error error in result.Errors) Console.Out.WriteLine(error.Message);