PDA

View Full Version : [OPEN] [OPEN-426] List returns wrong records on itemtap after Store.filterBy()



roady001
13 Oct 2010, 6:15 AM
List returns wrong records on itemtap after Store.filterBy()



var Proxy = new Ext.data.ScriptTagProxy(
{
type: 'ajax',
url: 'http://<remote_site>/prot.ashx?action=showlist',
reader: {
type: 'json',
root: 'data',
idProperty: 'protID'
}
});

Ext.regModel('protList', {
fields: [{name: 'protID', type:'integer'},
{name: 'name', type: 'string'},
{name: 'categoryname', type: 'string'}]
});
var ListStore = new Ext.data.Store({
id:'ListStore',
model: 'protList',
sorters: 'categoryname',
getGroupString: function (record) {
return record.get('categoryname');
},
proxy: Proxy,
autoLoad: true
});

var filterFn = function (record, id) {
if (record.get('name').toLowerCase().indexOf(Ext.getCmp('searchquery').getValue().toLowerCase()) > -1)
return true;
};

var searchBar = [{
xtype: 'toolbar',
id: 'searchBar',
ui: 'light',
hidden: false,
dock: 'top',
items: [{ xtype: 'spacer' }, {
xtype: 'textfield',
id: 'searchquery',
width: '60%',
maxWidth: 400,
fieldClass: 'searchField',
name: 'name',
placeHolder: 'Search',
showClear: true,
listeners: {
keyup: function (field, e) {
var key = e.browserEvent.keyCode;
// blur field when user presses enter/search
// which will trigger a change if necessary.
if (key === 13) {
field.blur();
}
if (Ext.getCmp('searchquery').getValue() != '')
{
Ext.getCmp('clearbutton').setDisabled(false); }
else {
Ext.getCmp('clearbutton').setDisabled(true);
}
},
blur: function () {
ListStore.filterBy(filterFn);
}
}
},
{
text: 'Clear',
id: 'clearbutton',
ui: 'drastic',
hidden: false,
disabled: true,
listeners:
{
tap: function () {
Ext.getCmp('searchquery').setValue();
ListStore.clearFilter();
}
}
}, { xtype: 'spacer' }
]
}];


// FOLLOWING IS part of tab from tabpanel

items: [{
width: Ext.is.Phone || Ext.is.iPad ? undefined : 300,
height: 500,
id: 'listviewer',
xtype: 'list',
loadingText: '',
store: ListStore,
tpl: '<tpl for="."><div class="protlistitem">{name}</div></tpl>',
itemSelector: 'div.protlistitem',
singleSelect: true,
grouped: true,
indexBar: false,
listeners: { 'itemtap': function (dv, i, el, e) {

var protID = dv.store.getAt(i).get('protID');
console.log(protID) // Not correct after filtering!
}
}
}]


After calling the ListStore.filterBy(filterFn) function, the list gets filtered correctly, however tapping on the items (event 'itemtap') in the list returns the wrong record. Well most of them anyway, it seems that only the last records is correct.

BrendanC
13 Oct 2010, 9:53 AM
Thanks for the bug report.

gaboo
24 Feb 2011, 5:14 AM
same problem when using grouped list

gcallaghan
25 Feb 2011, 10:40 AM
My workaround may work for this. see
http://www.sencha.com/forum/showthread.php?124911-Grouping-a-list-crews-up-node-record-linkage

michary
15 Dec 2011, 5:30 AM
Any news?

This is a major bug (it's impossible to use grouped list with an item tap) and open since over a year

howellzify
18 Feb 2012, 4:57 PM
I am running into the same issue. A grouped list returns the wrong index into the store. If the group causes the store to change its sort order the underlying store is not sorted. This leads to the wrong value being retrieved from the store. Any updates on this or ways to get around it? The only thing I can come up with is to pass the XML pre-sorted by the grouped by field.

howellzify
18 Feb 2012, 9:22 PM
I am running into the same issue. A grouped list returns the wrong index into the store. If the group causes the store to change its sort order the underlying store is not sorted. This leads to the wrong value being retrieved from the store. Any updates on this or ways to get around it? The only thing I can come up with is to pass the XML pre-sorted by the grouped by field.

After looking further I came up with a variation of a solution listed above. This item tap is from a List that is using a grouped store. I use one of the model fields to select the proper index from the store and then retrieve the corresponding record. Works perfectly.



itemtap: function(view, index, item, e){
var el = Ext.get(item);
var record = view.store.getAt(view.store.findExact('sermonname',el.select('div.lwflistheader').elements[0].textContent));
app.view.mediaDetail.update(record.data);
app.view.mediaDetail.show('pop');
}