Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
605
calculating summary using SummaryEvaluationMode manual with nested data source
posted

Hello.

I am using the SummaryEvaluationMode=Manual to do some custom summary calculations and have found it to be quite useful.  Now I have encountered a scenario where I have a nested data type, and I wish to do the summary on the child records.  It has occurred to me that there is no way -- to my knowledge -- for me to get the actual items that are being summarized.  The code examples of using this feature all use the grid.DataSource, because normally you're summing up the entire DataSource.

I examined the properties of the QuerySummaryResultEventArgs hoping that maybe something in there contains the actual records being summarized but I did not find anything.  I believe a property should be added to this event containing the records being summarized so that event handler code can grab them and pass them to the routine doing the summary calculation.

I've attached a solution illustrating this problem, can you please confirm there is no way to do this presently, or provide a workaround if possible?  thank you.

test.zip
Parents
  • 30945
    Verified Answer
    Offline posted

    Hello,

     

    Thank you for your post. I have been looking into the quesito that you are having and you can access the records, for which the summary is being applied, by using the e.Summary.ParentCollection.Records. This will returd a collection of DataRecords that are corresponding to the items of the child band for which the summary is calculated. You can use the collection to get the DataItems from the Records and to perfomr the calculations that you need. Here is how this can be done:

     

            private void XamDataGrid_QuerySummaryResult(object sender, QuerySummaryResultEventArgs e)

            {

                //var items = thegrid.DataSource as IEnumerable<Foo>;

                //Getting the DataItems for the child level

                var childItems = e.Summary.ParentCollection.Records.Select(r => (r as DataRecord).DataItem).ToList();

               

                //Calculating the sum of the records.

                double sum = childItems.Select(i => (int)i.GetType().GetProperty(e.Summary.SourceField.Name).GetValue(i, null)).Sum();

     

                //Setting the value

                e.SetSummaryValue(sum);

            }

     

    I am attaching a modified version of your sample that shows how you can use this approach.

     

    Please let me know if you need any further assistance on the matter.

    Sincerely,

    Krasimir, MCPD

    Developer Support Supervisor - XAML

    Infragistics

    www.infragistics.com/support

    test_1.zip
Reply Children
No Data