Alexander
Alexander

Reputation: 20224

Sencha grid aggregate store entries

Let's assume I have a store:

Buyer,Good,ItemCount,ItemPrice
{'Alice','Apple',5,$.25}
{'Bob','Pear',2,$.35}
{'Bob','Banana',5,$.25}
{'Bob','Pear',4,$.35}
{'Eve','Grapefruit',2,$.40}

And I have a grid in which to display this store's content, and at least a dozen functions scattered all over the place that change this store, changing filters, reloading data from the server, etc.

Is there a fast way to add another grid, which shows every good in a row and every buyer in a column, and how many items of that kind everyone bought in total? This grid should update whenever the original grid is updated.

The way I know, this would require another store, and then I would have to attach to the originalStore's datachanged and filterchanged event and populate the new store by hand every time? Or is there some other solution?

EDIT: I am now looking at pivot grid, as suggested by the first answer, and I have to expand my example a bit, as I stumbled upon a problem I didn't see before:

Buyer,Good,ItemCount,ItemPrice
{'Alice','Apple',5,$.25}
{'Bob','Pear',2,$.35}
{'Bob','Banana',5,$.25}
{'Bob','Pear',4,$.35}
{'Eve','Grapefruit',2,$.40}
{{'Alice','Bob'},'Candlelight Dinner Set',1,$45}
{'Eve',{'Ski mask','Baseball bat'},1,$65}
{'Francis',{'Ski mask','Ski poles'},1,$80}

Where I would want the dinner to show up at both Alice and Bob, and the products sold in a bundle to show up separately.

Upvotes: 3

Views: 931

Answers (1)

Aniketos
Aniketos

Reputation: 659

Try to use PivotGrid for your purpose:

var pivot = new Ext.grid.PivotGrid({
    store: yourStore,
    aggregator: 'sum',
    measure: 'ItemCount',
    leftAxis: [
        {
            dataIndex: 'Buyer'
        }
    ],
    topAxis: [
        {
            dataIndex: 'Good'
        }
    ]
});

Official Pivot Grid Links:

Upvotes: 1

Related Questions