PDA

View Full Version : [CLOSED][v3rc1.1] GroupingStore doesn't group if data not in group order



fzammetti
9 May 2009, 3:15 PM
Hi guys... I've got what I *think* is a bug (it could be that my expectations are incorrect though)... here's some test code;



<html>
<head>

<link rel="stylesheet" type="text/css"
href="../../ext/resources/css/ext-all.css">
<script type="text/javascript"
src="../../ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../ext/ext-all.js"></script>

<script>

var AccountRecord = Ext.data.Record.create([
{ name : "portfolio" }, { name : "name" }, { name : "type" },
{ name : "balance" }
]);

var accountsStore = new Ext.data.GroupingStore({
groupField : "type"
});

accountsStore.add(new AccountRecord({
portfolio : "test", name : "acc1", type : "Checking", balance : 11.22
}, "acc1"));
accountsStore.add(new AccountRecord({
portfolio : "test", name : "acc2", type : "Savings", balance : 33.44
}, "acc2"));
accountsStore.add(new AccountRecord({
portfolio : "test", name : "acc3", type : "Checking", balance : 55.66
}, "acc3"));

Ext.onReady(function() {

var viewport = new Ext.Viewport({ layout : "border",
items : [
{ region : "center", height : 400,
items : [
{ xtype : "grid", stripeRows : true, height : 300,
store : accountsStore,
sm : new Ext.grid.RowSelectionModel( { singleSelect : true } ),
columns : [
{ header : "Name", dataIndex : "name" },
{ header : "Type", dataIndex : "type" },
{ header : "Current Balance", align : "right",
dataIndex : "balance",
renderer : Ext.util.Format.usMoney }
],
view : new Ext.grid.GroupingView({
forceFit : true,
groupTextTpl : '{text} ({[values.rs.length]} ' +
'{[values.rs.length > 1 ? "Items" : "Item"]})'
})
}
]
}
]
});

});

</script>

</head>

<body></body>

</html>
When you run this, notice that the grouping does not work right... there are two Checking groups. Now... look at the accountsStore.add() calls and notice I add a Checking account, then a Saving account, then another Checking account... move the two Checking account add() calls together and re-run and you'll see the grouping works right. Note that I tried manually calling groupBy() on the store after the fact, but that doesn't help.

For my needs it's not the end of the world because I just throw an "order by" clause on my SQL query and everything works fine, but I certainly don't expect that I need to add my data in group order like that, meaning I should be able to add 500 accounts of various types in random order and the grouping should work right... at least, that's my expectation. If that expectation isn't accurate I'd sure like to understand why, but I'm posting this thinking it's probably a bug.

Thanks,
Frank

aconran
10 May 2009, 8:23 AM
Frank -

Use the addSorted method instead of add and ensure that you have an appropriate sort applied.