PDA

View Full Version : RowSelectionModel when extending GridPanel



mannyk
11 Aug 2010, 1:38 AM
Hello,

I want to add a doubleclick listener on my GridPanel. Also the id of the data entry should be passed to the function.
I tried the following but nothing happens because the listener is not been entered.

MyGrid = Ext.extend(MyGridUi, {
initComponent: function () {
MyGrid.superclass.initComponent.call(this);
selmodel: new Ext.grid.RowSelectionModel({
listeners: {
rowdblclick: function (sm, index, record) {
this.fireEvent('select', record.data.id);
},
scope: this
}
});
}
});
Strange but true, the following code works, but does not provide the id of the row entry.

MyGrid = Ext.extend(MyGridUi, {
initComponent: function () {
MyGrid.superclass.initComponent.call(this);
this.on({
rowdblclick: function (sm, index, record) {
this.fireEvent('select', record.data.id);
},
scope: this
});
}
});


Thanks for any help!
mannyk

11 Aug 2010, 4:49 AM
Your code is syntactically incorrect.


MyGrid = Ext.extend(MyGridUi, {
initComponent: function () {
MyGrid.superclass.initComponent.call(this);
selmodel: new Ext.grid.RowSelectionModel({
listeners: {
rowdblclick: function (sm, index, record) {
this.fireEvent('select', record.data.id);
},
scope: this
}
});
}
});

11 Aug 2010, 4:49 AM
try:



MyGrid = Ext.extend(MyGridUi, {
initComponent: function () {
MyGrid.superclass.initComponent.call(this);
this.selModel = new Ext.grid.RowSelectionModel({
listeners: {
rowdblclick: function (sm, index, record) {
this.fireEvent('select', record.data.id);
},
scope: this
}
});
}
});

mannyk
11 Aug 2010, 5:47 AM
Hello, and thank you very much for your help!

I tried the code but it worked only with the element 'rowselect'! If I paste the event 'rowdblclick', nothing happens.
Have you encountered such a behaviour before?

Regards,
mannyk

aconran
11 Aug 2010, 12:59 PM
RowSelectionModel does not expose an event named rowdblclick.

Ext.grid.GridPanel exposes an event named rowdblclick (http://dev.sencha.com/deploy/dev/docs/?class=Ext.grid.GridPanel&member=rowdblclick). You want to setup the event listener on the "this" object.



this.on('rowdblclick', function (grid, rowIdx, e) {

}, this);


You should also initialize your selModel before invoking the parent class implementation of initComponent.

Jack9
11 Aug 2010, 1:16 PM
To illustrate Mr. Conran's comment:




MyGrid = Ext.extend(MyGridUi, {
initComponent: function () {
this.selModel = new Ext.grid.RowSelectionModel({
//...

});

MyGrid.superclass.initComponent.call(this);
}
});

mannyk
12 Aug 2010, 3:08 AM
Hello and thank you for your numerous replies.

I tried this like you mentioned above:


MyGrid = Ext.extend(MyGridUi, {
initComponent: function () {
this.on('rowdblclick', function (grid, rowIdx, e) {
// do something
}, this);
MyGrid.superclass.initComponent.call(this);
}
});But again: the object e does not hold the data of the grid but just information about all keyboard keys.
I did not try the selectionModel since I need the rowdblclick event.

Jack9
12 Aug 2010, 7:51 AM
In that case you can do this:


MyGrid = Ext.extend(MyGridUi, {
initComponent: function () {
MyGrid.superclass.initComponent.call(this);
}
,listeners:{
rowdblclick:function(grid, rowIdx, e) {
// do something
}
}
});

aconran
12 Aug 2010, 11:55 AM
But again: the object e does not hold the data of the grid but just information about all keyboard keys.
I did not try the selectionModel since I need the rowdblclick event.

Yes, this is the Ext.EventObject and describes information about what you were clicking etc. (It's a wrapper around a browser event).

What are you trying to do? To get the current record you could do the following...


var ds = grid.getStore();
var record = ds.getAt(rowIdx);
console.dir(record.data);