I have a store like below
Ext.define('Result', {
extend: 'Ext.data.Model',
fields: [
{ name: 'state', type: 'string', mapping:0 },
{ name: 'product', type: 'string', mapping:1 },
{ name: 'quantity', type: 'int', mapping:2 }
{ name: 'price', type: 'int', mapping:3 }
]
});
var store = Ext.create('Ext.data.ArrayStore', {
model: 'Result',
groupField: 'state',
data: [
['MO','Product 1',50,40],
['MO','Product 2',75,50],
['MO','Product 3',25,60],
['MO','Product 4',125,70],
['CA','Product 1',50,50],
['CA','Product 2',100,40],
['WY','Product 1',250,40],
['WY','Product 2',25,50],
['WY','Product 3',125,86],
['WY','Product 4',175,83]
]
});
I want to calculate the average of quantity and price of every state group and show it into the grid . I have seen in the sencha documentation, there is a function like average(http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.Store-method-average) and I can Implement it like
store.avarage('quantity', true);
but it only gives the average of only one field .
How and I calculate the average of multiple fields depending on the group and show it in a grid.