PDA

View Full Version : MVC add click event on grid row



whisher
17 Jan 2012, 12:52 AM
Hi,
How can I set an click event handle on a grid row ?


Ext.define('SA.controller.Users', {
extend: 'Ext.app.Controller',
models: ['User'],
stores: [
'Users'
],
views: [
'user.List',
'user.Edit'
],
init: function() {
this.control({
'userlist': {
itemdblclick: this.editUser
},
'WHAT S THE RIGHT SELECTOR ?': {
//CLICK OR ITEMCLICK ?
itemclick: this.enableDeleteButton
},
'useredit button[action=save]': {
click: this.updateUser
}
});
},

editUser: function(grid, record) {
var view = Ext.widget('useredit');
view.down('form').loadRecord(record);
},
updateUser: function(button) {
var win = button.up('window'),
form = win.down('form'),
record = form.getRecord(),
values = form.getValues();
record.set(values);
win.close();
this.getUsersStore().sync();
},
enableDeleteButton: function(item) {
alert('hh');
}
});



Bye

ero
17 Jan 2012, 2:30 AM
I don't believe that grid has an event for click, but itemclick exists. I assume you're 'userList' is your grid:

'userList': {
itemclick: this.enableDeleteButton
}

enableDeleteButton: function(view, cell, cellIndex, record, row, rowIndex, e) {
//your code
}

whisher
17 Jan 2012, 2:39 AM
Thanks for the reply.
It works but I don't like very much having
a double selector like


this.control({
'userlist': {
itemdblclick: this.editUser
},
'userlist': {
itemclick: this.enableDeleteButton
},
'useredit button[action=save]': {
click: this.updateUser
}
});


Do you know if it's possible to use a more specific selector ?
I mean in the old style I could make 'userlist tr'

ero
17 Jan 2012, 2:57 AM
I guess I'm not exactly sure, but you can consolidate what you have as follows:



this.control({
'userlist': {
itemdblclick: this.editUser,
itemclick: this.enableDeleteButton
},
'useredit button[action=save]': {
click: this.updateUser
}
});

whisher
17 Jan 2012, 3:21 AM
It seems better and it works :) thanks again

ero
17 Jan 2012, 4:04 AM
No problem. You should mark the thread as answered to help others who might have the same question.