This week I had to create a complex report with 3 group levels and further sorting on 4 detail fields. The problem was that the 3rd group field was a date field, and the report never grouped on the date field, but created a new group with the same data field with each detail line. To exclude an obvious mistake: The dates do not contain any time data, they are purely dates.
E.g In the Northwind database you have a Categories, Products, Sales. The report would be grouped on Category name, Product name, Salesdate. The detail would be sorted on 3 other numerical fields.
The project is written in VS 2010 with LightSwitch 2011 and DevExpress XtraReports 11.1.
This is the result I would like to see
- Beverages
- Chai
- 2010-01-12
- 12,00 13,20 10,00
- 12,00 15,01 12,00
- 13,00 13,25 12,12
- 2010-01-13
- …
The problem was that the report never came out like that, instead
This is what I saw in the XtraReports print preview
- Beverages
- Chai
- 2010-01-12
- 12,00 13,20 10,00
- 2010-01-12
- 12,00 15,01 12,00
- 2010-01-12
- 13,00 13,25 12,12
- 2010-01-13
- …
Of course, my subtotals for the day (not shown here) were completely wrong too.
Solution: add computed property to convert date into string, the group on computed property
After checking the dates do not contain any hour information (and they did not). After having tried setting all kinds of combinations in the group and sorting properties, I decided to take another approach. In the Lightswitch datasource that served as the LightSwitchDataSource for the report, I added a computed field to convert the date field into a string like yyyyMMdd.
Here is an example of the Method for the computed property groupSalesdate:
partial void groupSalesdate_Compute(ref string result)
{
result = this.Salesdate.ToString("yyyyMMdd");
}
In my XtraReport designer, I replaced the group field for the 3rd level by the computed field. The field that is displayed can remain as it is , so that the date field can be formatted properly.
The final result is what I needed:
- Beverages
- Chai
- 2010-01-12
- 12,00 13,20 10,00
- 12,00 15,01 12,00
- 13,00 13,25 12,12
- 2010-01-13
- …
Remark
I have not tried this yet with VS2012 and DeveXpress release for 2012.
No comments:
Post a Comment