Aggregate by group



This online shopping cart example shows how to aggregate columns by groups.

Sometimes, Online buyers care pay more attention to how much money paid on certain category than total price. Sigma Grid could do them a favor.
  • All the aggregated are calculated in client side.
  • Interact with end users. Calculate aggregates by another group without any requests to server side.
  • This feature is also powerful when building a report. See report-like Sigma Grid.

Code

You need declare groupBy object in context. groupBy object contains keyName, groupsOrder, rowsOrder, aggregate and view.
  • keyName - Calculate aggregrates by which column.
  • groupsOrder - Specify how to sort among groups.
  • rowsOrder - Specify how to sort inside every group.
  • aggregate - To specify calculate which aggregate. Counld be sum,avg,max,min and count.

 

groupBy:{
    keyName:"from",
    groupsOrder:{column:"from",order:"asc"},
    rowsOrder:{column:"category",order:"asc"},
    aggregate:[ {column:"unitprice",exp:"sum",format:"#.00"}, {column:"quantity",exp:"sum",format:"#"} ], view:" oThis.rows[0].rowData.p$('from') + ' : Price sum is $' + oThis.values()['unitprice'] + ' and quantity sum is ' + oThis.values()['quantity']"
}

Aggregate by group

Tips 


Note: Don't set any columns sortable attribute to true, or you will make a mess of aggregate result.  

 


All contents are (c) Copyright 2005 - 2007, Sigma Software Inc. All rights Reserved