Ticket T302035
Visible to All Users

How best to report on child collection items in a XAF web report

created 9 years ago

I am looking for the best way to design a form layout (rather than a listing of detail records) report using the XAF Web Report designer (in a project using Entity Framework).  The report is based on a master object that has a collection of items.

Using the below objects as an example, I need to be able to design a form layout report so that it contains some of the fields from "Order", as well as specific items from its child collection(s).

For example:
=============================================
           MY REPORT

Order Number: [Order.OrderNumber]

Item1Notes: [Order.Items.DetailItems[1].Notes]     Item3Notes: [Order.Items.DetailItems[3].Notes]
Item11Notes: [Order.Items.DetailItems[11].Notes]

=============================================

Example class structure:

C#
-------------- Order -------------- string OrderNumber ItemList Items -------------- ItemList -------------- string ItemListName int CreatedBy IList<DetailItem> DetailItems -------------- DetailItem -------------- string ItemName string Notes

Can you suggest the best way to accomplish this?

I though perhaps using a calculated field could work, but I don't see that available in the web XAF Report Designer.  Perhaps scripting could work, but I don't see any support for that in the web report designer.

I would prefer to be able to handle this within the report definition somehow, but if that is not possible, could I use the model designer to create some calculated fields that reference an item in a collection (i.e. Order.Items.DetailItems[5].Notes).  Finally, if this is an option, is it possible to reference items in a collection by a property value rather than by index?  (i.e. somehow use the ItemName => Order.Items.DetailItems[DetailItem.ItemName])

Thanks!

Comments (1)

    If the objects are joined by relationships then that is easy. Simply use the Field Explorer in the report designer.In your case, if Order and Detailitem is related then if you click the arrow to expand the field you will see the columns. Drag the column you want to the designer surface.

    Answers approved by DevExpress Support

    created 9 years ago (modified 9 years ago)

    Hi Saif,

    It is impossible to access a certain object in a child collection by its index. Our Reporting tools are intended to display collections in this scenario, but not single objects. You can either create the corresponding property at the level of the Order class or use CalculatedFields to obtain the required value from the nested collection.

    In v14.2, ASPxReportDesigner had a limited set of features, because this is a new yet intensively developed control. In particular, CalculatedFields and Scripts were not supported in this version. However, these features are supported in v15.1. Thus, if you need this functionality, I recommend that you consider updating to a newer version.

      Show previous comments (3)
      DevExpress Support Team 9 years ago

        Hi Richard,

        As I mentioned before, it is impossible to access child values by their indices. At the same time, you can create a CalculatedField instance, create the OnGetValue script for it, and perform the required actions in this script. Let's take your previous description of your data structure. If your report is bound to Invoice, which has the CustomFieldList property, your OnGetValue script implementation will look like this:

        C#
        private void calculatedField_GetValue(object sender, GetValueEventArgs e) { Invoice inv = e.Row as Invoice; e.Value = inv.CustomFieldList[10]; }

        You can also perform the same actions for a particular control. Create the OnBeforePrint script for the corresponding label, obtain the current Invoice instance using the GetCurrentRow method, and then pass the required value to the XRLabel.Text property:

        C#
        private void label_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { XRLabel label = sender as XRLabel; Invoice inv = label.Report.GetCurrentRow() as Invoice; label.Text = inv.CustomFieldList[10].ToString(); }
        RM RM
        Richard Millard 9 years ago

          Thank you!  That sounds like it will work, but could you please point me to some documentation on how to use calculated fields in the web report designer?  I've found documentation for the windows version, but I can't find how to place a calculated field on a report (or link a text box to a calculated field).  I know this must be super simple, but I can't find it.
          I can create a calculated field (under the "Data" group when the report is selected).  However, once I've done that, I cannot find that calculated field when trying to link a text box to the calculated field using the "Data Binding" selection box.

          Vasily (DevExpress Support) 9 years ago

            Hi Richard,

            To process your recent post more efficiently, I created a separate ticket on your behalf: T305167: How to use calculated fields in a Web Report Designer. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.