c# - TotalSummary of GroupSummaries in Devexpress -
i have aspxgridview
this:
is there way calculate total of groupsummary
totalsummary
without grouping.
groupsummary's summerytype="average"
for example:
mus_k_isim groupsummary[risk_eur] 2m lojİstİk 123.456 aba lojİstik 234.567
then want totalsummary
of risk_eur
column 123.456 + 234.567 = 358023
.
note: want calculation normal gridview. not doing 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 grid:
what avarage of 123 number customer = 50 + 100 + 60 = 210/3= 70 avarage of 124 number customer = 60/1=60 avarage of 125 number customer = 20 + 40 = 60/2= 30
and totalsummary of price = 70 + 60 + 30 = 160
how can that? or code about? function should use?
i see 2 different solutions:
1) implement data management manually:
a) sort data pseudo group column; b) browse through sorted data list, calculate summary values manually , show value;
2) create new grid on page, bind data, group required column, fetch summary values , dispose it.
i did not check second approach, not see reason on why approach should not work.
update
it possible set summary value if using custom summary. can done within customsummarycalculate event handler. obtain summary values, can use following code:
double total = 0; for(int = 0; < aspxgridview1.visiblerowcount; ++) { total += convert.todouble(aspxgridview1.getgroupsummaryvalue(i, somesummaryitem)); }
you should implement this.
update 2 ok, think have found effective solution problem. let me explain. first, necessary use custom summary explained in custom summary topic. using customsummarycalculate event handler, necessary collect data dictionary object, key contains customer_no field value, value - list of price values customer. finally, necessary calculate resulting summary. below complete code, both aspx , c#. hope, helpful 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 = 0; < current.value.count; i++) sum += current.value[i]; result += sum / current.value.count; } return result; }
Comments
Post a Comment