PDA

View Full Version : [FIXED] Ext.dataview.List's multiselect mode does not work



yoh.suzuki
21 Oct 2011, 3:48 PM
Ext.dataview.List's multiselect mode does not work (both 'MULTI' and 'SIMPLE'.) It will not let you select anything at all.

Here's some code that demonstrates this bug:


Ext.setup({
onReady: function() {
Ext.define('Contact', { extend: 'Ext.data.Model', fields: ['firstName', 'lastName'] });
Ext.create('Ext.dataview.List', {
mode:'MULTI',
fullscreen: true,
itemTpl: '<div class="contact">{firstName} <strong>{lastName}</strong></div>',
store: Ext.create('Ext.data.JsonStore', {
model: 'Contact',
sorters: 'lastName',
getGroupString: function(record) {
return record.get('lastName')[0];
},
data: [
{firstName: 'Tommy', lastName: 'Maintz'},
{firstName: 'Rob', lastName: 'Dougan'},
{firstName: 'Ed', lastName: 'Spencer'}
]
})
});
}
});


At least part of the problem is that the function doMultiSelect from Ext.mixin.Selectable does not execute the following line until after it's already looked for the length of the records array (this may need to happen first):


records = !Ext.isArray(records) ? [records] : records;

However, even fixing that doesn't let you select more than one at a time. I'm going to get back to this problem later this weekend. I'll post a workaround if I find one.

yoh.suzuki
24 Oct 2011, 1:41 PM
Here's a workaround. (This is not ideal. It would be better to configure a regular list with mode:'MULTI', which I hope we'll be able to do shortly!)


Ext.define('Ext.dataview.MultiSelectList', {
extend : 'Ext.dataview.List',
config : {
mode : 'MULTI',
deselectOnContainerClick : false
},
doMultiSelect : function(records, keepExisting, suppressEvent) {
records = !Ext.isArray(records) ? [records] : records;
if(records === null || this.getLocked()) {
return;
}
var me = this, selected = me.getSelected(), ln = records.length, change = false, i = 0, record, smap = {}, s, deselect = [];

// figure out which items are already selected (so we can deactivate them)
for(s in selected.items) {
smap[selected.items[s].id] = selected.items[s]
}
for(; i < ln; i++) {
record = records[i];
change = true;
if(( id = record.id) in smap) {
deselect.push(smap[id]);
} else {
me.setLastSelected(record);
me.getSelected().add(record);
if(!suppressEvent) {
me.setLastFocused(record);
}
me.onItemSelect(record, suppressEvent);
}
}
me.deselect(deselect, true);
this.fireSelectionChange(change && !suppressEvent);
}
});

Jamie Avins
31 Oct 2011, 11:27 AM
Definite bug, thank you for the report.