PDA

View Full Version : CellEditing Listener...



Forza Bo
24 Aug 2012, 12:31 PM
I must be doing something really dumb, but I can't figure out how to get Ext.grid.plugin.CellEditing to respond an the edit event. Or any event. I must not be adding the listener correctly. Or in the right place. Or something.

Here's one of the many things I've tried (fragment):


items: [{ xtype: 'grid',
title: 'plans',
store: me.plans,
columns: [
{ header: 'id', dataIndex: 'id', width : 32},
{ header: 'Name', dataIndex: 'name', flex: 1, field : 'textfield' },
{ header: 'Description', dataIndex: 'description', flex: 1, field : 'textfield'},
{ header: 'System', dataIndex: 'system_name', flex: 1, field : 'textfield',}
],
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 2,
listeners: [
{edit: function(){console.log("booooo")}}
]
})

],

}],

What I would like to do is allow the inline editing function on most cells, but override on a few others. For example, The system name column needs to correlate to a system id table... anyway...

scottmartin
24 Aug 2012, 1:08 PM
See if this works for you:




Ext.onReady(function(){

var store = Ext.create('Ext.data.Store', {
fields : ['name', 'email', 'change'],
data : {'items' : [
{ 'name' : 'Lisa', 'email' : 'lisa@simpsons.com', 'change' : 100 },
{ 'name' : 'Bart', 'email' : 'bart@simpsons.com', 'change' : -20 },
{ 'name' : 'Homer', 'email' : 'home@simpsons.com', 'change' : 23 },
{ 'name' : 'Marge', 'email' : 'marge@simpsons.com', 'change' : -11 }
]},
proxy : {
type : 'memory',
reader : {
type : 'json',
root : 'items'
}
}
});

var editor = {
xtype: 'textfield',
allowBlank: false
};

var columns = [
{ header : 'Name', dataIndex : 'name', locked: true, editor: editor },
{ header : 'Email', dataIndex : 'email', flex : 1, editor: editor },
{ header : 'Change', dataIndex : 'change', editor: editor }
];

var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1,
listeners: {
edit: function(){
console.log('boo-who?');
}
}

});

var grid = Ext.create('Ext.grid.Panel', {
title : 'Simpsons',
store : store,
columns : columns,
height : 200,
width : 400,
renderTo : Ext.getBody(),

plugins: [ cellEditing ]
});

});


console:

> boo-who?

Scott.

Forza Bo
29 Aug 2012, 9:14 AM
Scott,

Thank you for the working example. My mistake was adding square brackets around the listeners argument. I am still a little fuzzy why it shouldn't get brackets whereas items, for instance, does... but it doesn't matter, it works!

Thanks again,

--Bo

scottmartin
29 Aug 2012, 9:49 AM
A listeners is an object, whereas items is an object or array of objects.

Scott.

Forza Bo
29 Aug 2012, 11:18 AM
Thank you for de-fuzzifying that for me, Scott!

Cheers,

--Bo