PDA

View Full Version : Report error "column.getEditor is not a function" when I setEditor to a column?



hexawing
30 Oct 2011, 6:24 AM
My code is like this:



var my_grid = Ext.getCmp("my_grid");
var myEditor = my_grid.columns[0].getEditor();
my_grid.columns[3].setEditor(myEditor);


column.getEditor is not a function
http://localhost/javascripts/ext/ext-all-debug.js
Line 79363

in source code,


field = column.getEditor(null, {
xtype: 'displayfield',
getModelData: function() { //<-this line is 79363
return null;
}
});


my ExtJS version is 4.0.7 and the same problem in 4.0.2

lucasguaru
31 Oct 2011, 3:50 AM
Looks like you're trying to use the same editor for two columns. Is that right?
If so, what you have to do is bind your function to the column


{
text : "Valor",
name : 'colunaValor',
//width : 75,
sortable : true,
dataIndex : 'valor',
width : 180,
renderer : Ext.Function.bind(this.renderCell, this),
getEditor : Ext.Function.bind(this.getCellEditor, this)
}

In this function you return the appropriate editor (I did it according to the column type)


getCellEditor : function(record, column) {
return this.editors[record.get('type')];
}

This is how you create your editors :


this.editors = {
'date' : Ext.create('Ext.grid.CellEditor', {
field : Ext.create('Ext.form.field.Date', {
//allowBlank : false,
selectOnFocus : true
})
}),
'string' : Ext.create('Ext.grid.CellEditor', {
field : Ext.create('Ext.form.field.Text', {
//allowBlank : false,
selectOnFocus : true
})
}),
'number' : Ext.create('Ext.grid.CellEditor', {
field : Ext.create('Ext.form.field.Number', {
//allowBlank : false,
selectOnFocus : true
})
}),
'int' : Ext.create('Ext.grid.CellEditor', {
field : Ext.create('Ext.form.field.Number', {
//allowBlank : false,
selectOnFocus : true
})
}),
'boolean' : Ext.create('Ext.grid.CellEditor', {
allowBlank : false,
field : Ext.create('Ext.form.field.ComboBox', {
editable : false,
store : [ [ true, 'Sim' ], [ false, 'Não' ] ]
})
})
};

hexawing
31 Oct 2011, 4:52 PM
Emm, perhaps my expression is incorrect...I just want to set a different editor to a column, but I don't know what kind of "editor" should I write(no matter how I wrote the editor, I got the same error), so I tried to get an editor from other column. And it didn't work either...

hexawing
4 Nov 2011, 1:37 AM
In firebug, I found this about the "column"'s property:

$className "Ext.form.field.Text"

sure it hasn't the "setEditor" method. In API, setEditor is a method of Ext.grid.column.Column, so I think this is a bug...

hexawing
4 Nov 2011, 4:50 PM
http://jsfiddle.net/hexawing/mf2jH/5/

As the code snippet above, is my commented code correct? It cannot work if I uncomment that line.

Can anyone help me?

taylon
6 Mar 2012, 8:39 AM
I'm positive this is not a best practice method (especially after all the "use itemId instead of id" posts), but I've found you can give the editor of the column an id and just reference that. Below is some rough example code to dynamically set a column to allowBlank or not. It should work for anything that goes into the editor. Just get the id, set the property, and doComponentLayout() on the grid.

Incidentally it looks like my issue might be fixed in 4.1 http://www.sencha.com/forum/showthread.php?154135-setEditor-cannot-work-in-rowEditing&langid=1 but since it's still beta I can't swap over to it just yet.

Hope it helps.



var myGrid = Ext.create('Ext.grid.Panel', {
plugins: [rowEditing],
width: '100%',
height: 450,
store: myStore,
id: 'myGrid',
columnLines: true,
columns: [{
text: 'My Column Text',
itemId: 'myColumn',
dataIndex: 'myData',
editor: {
xtype: 'textfield',
id: 'myColumnEditor'
}]
});

// Do stuff begin
// ...
// Do stuff end

if (someVariable === 'Blah' ) {
Ext.getCmp('myColumnEditor').allowBlank = true;
else
Ext.getCmp('myColumnEditor').allowBlank = false;
}

Ext.getCmp('myGrid').doComponentLayout();