TotalSummary of GroupSummaries at Devexpress

I have an ASPxGridview like this:

enter image description here

Is it possible to compute Total GroupSummary to TotalSummary without grouping .

 GroupSummary SummeryType="AVERAGE" 

Example:

 MUS_K_ISIM GroupSummary[RISK_EUR] 2M LOJฤฐSTฤฐK 123.456 ABA LOJฤฐSTIK 234.567 

Then I want the TotalSummary column RISK_EUR be 123.456 + 234.567 = 358023 .

NOTE : I only need this calculation with a regular gridview. Do not do with grouping.

Another example:

 Customer_No Customer_Name Price 123 aaa 50 123 aaa 100 123 aaa 60 124 bbb 60 125 ccc 20 125 ccc 40 

I want with this grid:

 What is avarage of 123 number customer = 50 + 100 + 60 = 210/3= 70 What is avarage of 124 number customer = 60/1=60 What is avarage of 125 number customer = 20 + 40 = 60/2= 30 

And then TotalSummary of Price = 70 + 60 + 30 = 160

How can i do this? Or what is this code about? What function should I use?

+6
source share
2 answers

I see two different solutions:

1) perform data management manually:
a) sort data by pseudo-group column; b) view the sorted list of data, calculate the final values โ€‹โ€‹manually, and finally show this value;

2) create a new grid on the page, associate it with data, a group by the required column, get the final values โ€‹โ€‹and, finally, dispose of it.

I have not tested the second approach, but I see no reason why this approach should not work.

UPDATE

Only the final value can be set if you use your own resume. This can be done in the CustomSummaryCalculate event handler. You can also use the following code to get summary values:

 double total = 0; for(int i = 0; i < ASPxGridView1.VisibleRowCount; i ++) { total += Convert.ToDouble(ASPxGridView1.GetGroupSummaryValue(i, someSummaryItem)); } 

You should implement something like this.

Update 2 Okay, I think I found the most effective solution to this problem. Let me explain. First, you must use your own resume, as explained in the User Summary . Using the CustomSummaryCalculate event handler, it is necessary to collect data into a Dictionary object, whose key contains the value of the Customer_No field, the value is a list of price values โ€‹โ€‹for this Client. Finally, you need to calculate the final resume. Below is the full code, both ASPx and C #. Hope this will be helpful for you.

  <dx:ASPxGridView ID="ASPxGridView1" runat="server" OnCustomSummaryCalculate="ASPxGridView1_CustomSummaryCalculate"> <TotalSummary> <dx:ASPxSummaryItem FieldName="Price" SummaryType="Custom" ShowInColumn="Price" /> </TotalSummary> <Settings ShowFooter="True" /> </dx:ASPxGridView> 

...

 using System; using System.Collections.Generic; using System.Data; using System.Collections; protected void Page_Init(object sender, EventArgs e) { ASPxGridView1.DataSource = GetDataSource(); ASPxGridView1.DataBind(); } private object CreateDataSource() { DataTable table = new DataTable(); table.Columns.Add("Customer_No", typeof(int)); table.Columns.Add("Price", typeof(int)); table.Rows.Add(new object[] {123, 50 }); table.Rows.Add(new object[] {123, 100 }); table.Rows.Add(new object[] {123, 60 }); table.Rows.Add(new object[] {124, 60 }); table.Rows.Add(new object[] {125, 20 }); table.Rows.Add(new object[] {125, 40 }); return table; } private object GetDataSource() { if(Session["data"] == null) Session["data"] = CreateDataSource(); return Session["data"]; } Dictionary<int, List<int>> dict; protected void ASPxGridView1_CustomSummaryCalculate(object sender, DevExpress.Data.CustomSummaryEventArgs e) { if(e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Start) dict = new Dictionary<int, List<int>>(); if(e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Calculate) { int customer_No = Convert.ToInt32(e.GetValue("Customer_No")); List<int> list; if(!dict.TryGetValue(customer_No, out list)) { list = new List<int>(); dict.Add(customer_No, list); } list.Add(Convert.ToInt32(e.GetValue("Price"))); } if(e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Finalize) { e.TotalValue = CalculateTotal(); } } private object CalculateTotal() { IEnumerator en = dict.GetEnumerator(); en.Reset(); float result = 0; while(en.MoveNext()) { KeyValuePair<int, List<int>> current = ((KeyValuePair<int, List<int>>)en.Current); int sum = 0; for(int i = 0; i < current.Value.Count; i++) sum += current.Value[i]; result += sum / current.Value.Count; } return result; } 
+3
source

Do your sql return value:

 select (select SUM(x) from foo f2 where f1.x = f2.x) as sum, f1.x from foo f1 
0
source

Source: https://habr.com/ru/post/887764/


All Articles