PDA

View Full Version : viewIndex wrong value when adding item on grouped list



elmasse
27 Jun 2011, 11:39 AM
When a new item is added to a grouped list it has incorrect viewIndex value in one special case: If you have more than 1 group and you add a new item in a group in the middle, the last added item gets wrong indexValue. The latest item in the list (visually) points to the latest item added.

Steps:
1.- Create a list with grouped items.


//pseudo-code
var store = new Ext.data.Store({
model: 'Product',
groupField: 'category'
});
var list = new Ext.List({
store: store,
grouped: true
});


2.- Add items to list


//pseudo-code
var prods = [
{name:'Prod 1', category: 'Cat A'},/*..*/{name:'Prod 9', category: 'Cat A'},
{name:'Prod 1', category: 'Cat B'},/*..*/{name:'Prod 8', category: 'Cat B'},
{name:'Prod 1', category: 'Cat C'},/*..*/{name:'Prod 9', category: 'Cat C'}
]
store.add(prods);

store.add( {name:'Prod 9', category: 'Cat B'});



3.- Click on the latest element in the list view. It should be {name:'Prod 9', category: 'Cat C'}
Instead itemTap or even disclose event retrieves: {name:'Prod 9', category: 'Cat B'}

There is a bug, you shouldn't call updateIndexes from DataView, it needs to be override on List implementation.

elmasse
27 Jun 2011, 1:30 PM
This is what I call a really ugly fix! But it works:



//Declare Store with groupField (or getGroupedString using a field)
var store = Ext.data.Store({
model: 'Products',
groupField: 'category',
/*sort your data with same group criteria*/
sorters: 'category'
});

store.add(/*something here*/);
store.sort(); // <- nasty ugh? but it works


I'm using this until this bug gets fixed.

Bests,
Max