Total of GroupSummary to TotalSummary in DevExpress

社会主义新天地 提交于 2019-12-12 04:15:47

问题


In my ASPxGridView,

I getting total simply IPOTEK column in footer with this code;

<TotalSummary>
<dx:ASPxSummaryItem FieldName="IPOTEK" SummaryType="SUM" ShowInGroupFooterColumn="IPOTEK" DisplayFormat="n0" />
</TotalSummary>

And i getting average value of IPOTEK column when i grouping in Group's footer.

<GroupSummary>
 <dx:ASPxSummaryItem FieldName="IPOTEK" SummaryType="AVERAGE" ShowInGroupFooterColumn="IPOTEK" DisplayFormat="n0" />
</GroupSummary>

Everything is OK. For example when i grouping with, it looks like this; (IPOTEK column is starting 109.827)

What i want is; in TotalSummary, only total of GroupSummary values for IPOTEK column.

Rigth now, for this data adding TotalSummary value 109.827 * 3 = 329.481 (GroupSummary * 3)

What i want, for this data adding only and only GropupSummary value to TotalSummary.

How can i do that?

Best Regards, Soner


回答1:


Well, there is no a straightforward solution to this task. I see two alternatives:

1) use a custom summary for the footer summary and at the stage of the DevExpress.Data.CustomSummaryProcess.Finalize try to run through all group rows, obtain the corresponding summary values and sum them. To run through group rows, use the following code:

protected void ASPxGridView1_CustomSummaryCalculate(object sender, DevExpress.Data.CustomSummaryEventArgs e) {
    if(e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Finalize) { 
        ASPxGridView grid = sender as ASPxGridView;
        double total = 0;
        for(int i = 0; i < grid.VisibleRowCount; i++) 
            if(grid.IsGroupRow(i)) 
                total += Convert.ToDouble(grid.GetGroupSummaryValue(i, grid.GroupSummary[0]));
        e.TotalValue = total;
        e.TotalValueReady = true;
    }
}

2) use a label within the column's FooterTemplate container and handle the GridView's PreRender and BeforeGetCallbackResult to set this label value. The value should be calculated using the code above.

I hope, this helps.

UPDATE

why are using this code:

if (grid.IsGroupRow(7))

7 is a visibleRowIndex, you should pass the i parameter there



来源:https://stackoverflow.com/questions/5895289/total-of-groupsummary-to-totalsummary-in-devexpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!