You have to hack your hack...
Here's the code that would do what you ask for the "Full" column:
{text: 'Full', dataIndex:'isFull', stopSelection: false, width: 72,
renderer: function (value, meta, record) {
return '<center><input type="checkbox" name="checkbox"' + (value ? 'checked' : '')
+ ' onclick="'
+ 'var g = Ext.getCmp(\'button-grid\'), s = g.store, r = s.getAt(s.findExact(\'id\',\'' + record.get('id') + '\'));'
+ 'r.set(\'isFull\', this.value); '
+ 'g.getSelectionModel().select(r, true)' // second argument is keepExisting
+ '"';
}},
I've already told that, but using a regular CheckColumn
and a RadioColumn
would allow you to work with events, and save you this kind of headaches...
Edit Fixed code:
{text: 'Full', dataIndex:'isFull', stopSelection: false, width: 72,
renderer: function (value, meta, record) {
return '<center><input type="checkbox" name="checkbox"' + (value ? 'checked' : '')
+ ' onclick="'
+ 'var g = Ext.getCmp(\'button-grid\'), s = g.store, r = s.getAt(s.findExact(\'id\',\'' + record.get('id') + '\'));'
// changed this.value to this.checked
+ 'r.set(\'isFull\', this.checked); '
// selecting the row only if the checkbox is being checked -- not if it is unchecked
+ 'if (this.checked) g.getSelectionModel().select(r, true);' // second argument is keepExisting
// you'll probably want to use a custom method in your grid, instead of the selectionchangeevent (see bellow)
+ 'g.notifySelectionChange();'
// closed the tags, one never knows...
+ '" /></center>';
}}
As said in the comments above, you'll probably want to use a custom method instead of relying on the selectionchange
event. The reason is that this event won't be fired when a "full" checkbox is unchecked. We could simulate the firing of the event ourselves but that would be very dangerous for any existing or would-be code that would rely on this event... The custom method is safe and we have full control over it :)
Just add it to your grid like this:
var grid4 = Ext.create('Ext.grid.Panel', {
// ...
notifySelectionChange: function() {
// move the content of your listener here
}
});