PDA

View Full Version : Hooking into CheckboxModel select event in Controller?



RandomRunner
21 Aug 2012, 2:00 AM
I wish to use the CheckboxModel for my grid and hook into the various listeners using the controller. Unfortunately the only way I have it working so far is to define the listeners in the view.



Ext.define(MyApp.MyGrid', {
extend: 'Ext.grid.Panel',
selModel: {
selType: 'checkboxmodel',
mode: 'MULTI',
checkOnly: true,
listeners: {
select: function (model, record, index, eOpts) {
Ext.Msg.alert('', "You've clicked " + index.toString());
}
}
},
……
});


How can I achieve this from within the Controller? I have tried giving the selModel an itemId and reference that from the Controller but it doesn’t seem to work


init: function () {
this.control({
'grid #checkboxselector': {
select: this.showSelection
}


and I have also tried to create the selection model in the onLaunch of the controller and then adding it to the grid and call grid.doLayout but the checkbox column doesn’t appear.



onLaunch: function() {
var selModel = Ext.create('Ext.selection.CheckboxModel', {
selType: 'checkboxmodel',
mode: 'MULTI',
checkOnly: true,
listeners: {
select: function() ......
}
});
Ext.ComponentQuery.query('grid')[0].selModel = selModel;
Ext.ComponentQuery.query('grid')[0].doLayout();
}


What have I missed here? Thanks in advance

redraid
21 Aug 2012, 2:49 AM
add grid alias:


Ext.define(MyApp.MyGrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.mygrid',
selModel: {
selType: 'checkboxmodel',
mode: 'MULTI',
checkOnly: true,
listeners: {
select: function (model, record, index, eOpts) {
Ext.Msg.alert('', "You've clicked " + index.toString());
}
}
},
……
});

control:


'mygrid': {
select: this.showSelection
}

RandomRunner
21 Aug 2012, 3:02 AM
Thanks redraid, I was too focused on the actual selection model listener and didn't realise that these events are in fact fired by the grid. Thank you for your help, works a treat!