PDA

View Full Version : me.grid is undefined



crocop21
25 May 2012, 6:47 AM
Hi all, i need some help, i try to add a new record with the event click to my grid with MVC, that means i need to instantiate an object of my plugin.CellEditing for can Cancel and Start Edit.
This the error:
me.grid is undefined


chrome://firebug/content/blank.gif

viewEl = me.grid.getView().getEl(me.getActiveColumn());





something like this is my function in my controler
init: function(application) {
this.control({
"#edit": {
click: this.onButtonClick
}



onButtonClick: function(button, e, options) {
var gridd = Ext.getCmp('p');
var store = gridd.getStore();
var id = Ext.id();
var r = Ext.create('MyApp.model.Plant', {
id: Ext.id(),
name:'',
age:'',
country:''
});
var edit = Ext.create('Ext.grid.plugin.CellEditing', { });
edit.cancelEdit();
store.insert(0, r);
edit.startEdit(0, 0);
}


Thanks alot...

Tim Toady
25 May 2012, 7:21 AM
Instead of creating your CellEditing there, try specifying it in your grid's plugins.
eg


plugins: [
{
ptype: 'cellediting'
}
]

crocop21
25 May 2012, 7:43 AM
U mean something like this

Ext.create('Ext.grid.plugin.CellEditing', {
plugins: [
{
ptype: 'cellediting'
}
]
});

cellediting.cancelEdit();
store.insert(0, r);
cellediting.startEdit(0, 0);

I have the error

cellediting is not defined


chrome://firebug/content/blank.gif

cellediting.cancelEdit();

Tim Toady
25 May 2012, 7:50 AM
No, specify the plugins on the grid and delete your Ext.create

crocop21
25 May 2012, 7:58 AM
On the grid

On my grid is like this:

Ext.define('MyApp.view.MyGridPanel', {
extend: 'Ext.grid.Panel',
alias: 'widget.p',

height: 250,
width: 400,
title: 'My Grid Panel',
store: 'MyJsonStore',

initComponent: function() {
var me = this;

Ext.applyIf(me, {
viewConfig: {
id: 'p'
},
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
ptype: 'cellediting'
})
],
....

Tim Toady
25 May 2012, 8:03 AM
Sorry. I just edited my last post. What I mean is the plugin should not be in another cellediting instance. Just put the plugin array I specified previously directly into your grid. You can use Ext.create instead of ptype though as seen in the api for cellediting. I personally prefer ptype though.

crocop21
25 May 2012, 8:10 AM
Sorry. I just edited my last post. What I mean is the plugin should not be in another cellediting instance. Just put the plugin array I specified previously directly into your grid. You can use Ext.create instead of ptype though as seen in the api for cellediting. I personally prefer ptype though.

But how will know my event click when need to cancelEdit() and startEdit() if i am not doing any reference to my grid.plugin.CellEditing ?? Remember i am doing in MVC so have to call the objects from the controller i think..
Thanks for u help.

Tim Toady
25 May 2012, 9:33 AM
Set a pluginId

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.AbstractComponent-method-getPlugin

Srikanth474
25 May 2012, 9:42 AM
try using
edit.startEditByPosition({row: 0, column: 0});

crocop21
25 May 2012, 10:30 AM
Set a pluginId

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.AbstractComponent-method-getPlugin (http://docs.sencha.com/ext-js/4-1/#%21/api/Ext.AbstractComponent-method-getPlugin)

I did, all look perfect in the code but i have this error now, in theory should work....dont know what is the problem:
plugins is undefined


chrome://firebug/content/blank.gif

ln = plugins.length;



var gridd = Ext.getCmp('p');
var store = gridd.getStore();
var id = Ext.id();
var r = Ext.create('MyApp.model.Plant', {
id: Ext.id(),
name:'',
age:'',
country:''
});
var plugin= gridd.getPlugin('cellplugin');
plugin.cancelEdit();
store.insert(0, r);
plugin.startEdit(0, 0);



This is the grid with the plugin:

Ext.define('MyApp.view.MyGridPanel', {
extend: 'Ext.grid.Panel',
alias: 'widget.p',

height: 250,
width: 400,
title: 'My Grid Panel',
store: 'MyJsonStore',

initComponent: function() {
var me = this;

Ext.applyIf(me, {
viewConfig: {
id: 'p'
},
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
ptype: 'cellediting',
pluginId: 'cellplugin'
})
],

Tim Toady
25 May 2012, 11:08 AM
gridd is not your grid. It is a tableview on your grid. Honestly it is best not to use ids. The preferred way to do it would be to specify a refs config in your controller and then call this.getSomeRef in your controller
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Controller-cfg-refs
You should probably have a better named alias that describes what your view is as well.

Don't worry about that until we have this working though. Delete your viewConfig and put the id on your grid for the time being. Then getPlugin will work

crocop21
25 May 2012, 12:04 PM
gridd is not your grid. It is a tableview on your grid. Honestly it is best not to use ids. The preferred way to do it would be to specify a refs config in your controller and then call this.getSomeRef in your controller
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Controller-cfg-refs (http://docs.sencha.com/ext-js/4-1/#%21/api/Ext.app.Controller-cfg-refs)
You should probably have a better named alias that describes what your view is as well.

Don't worry about that until we have this working though. Delete your viewConfig and put the id on your grid for the time being. Then getPlugin will work

U mean i cant use this: var gridd = Ext.getCmp('p');
then how can get my grid? because i need for send the changes to my function of saving

var pa = Ext.create('MyApp.view.MyGridPanel',{});
var id = Ext.id();
var r = Ext.create('MyApp.model.Plant', {
id: Ext.id(),
name:'',
age:'',
country:''
});
var plugin= pa.getPlugin('cellplugin');

plugin.cancelEdit();
store.insert(0, r);
plugin.startEdit(0, 0);

Tim Toady
25 May 2012, 12:30 PM
Ext.getCmp will grab any component by its id. The problem in your situation is you put that id on the view, not the grid.

crocop21
25 May 2012, 12:47 PM
Ext.getCmp will grab any component by its id. The problem in your situation is you put that id on the view, not the grid.

How to get the grid then?

Tim Toady
25 May 2012, 12:58 PM
....

If you move the id from your view to the grid your getCmp will work

crocop21
25 May 2012, 1:11 PM
....

If you move the id from your view to the grid your getCmp will work
I did is fine but still can edit...and i have this error:
record.get is not a function

record.get is not a function


chrome://firebug/content/blank.gif

value = record.get(columnHeader.dataIndex),



var gridd = Ext.getCmp('p');
var store = gridd.getStore();
var id = Ext.id();
var r = Ext.create('MyApp.model.Plant', {
id: Ext.id(),
name:'',
age:'',
country:''
});
var plugin= gridd.getPlugin('cellplugin');
plugin.cancelEdit();
store.insert(0, r);
plugin.startEdit(0, 0);

Tim Toady
25 May 2012, 5:30 PM
startEdit wants a record and column. This previous post is what you want for this step. Just replace edit with the correct variable name.

try using
edit.startEditByPosition({row: 0, column: 0});

crocop21
28 May 2012, 7:49 AM
startEdit wants a record and column. This previous post is what you want for this step. Just replace edit with the correct variable name.
Thanks alot ;) its work startEdit!, only canceledit why can still editing the grid?

Tim Toady
29 May 2012, 5:45 AM
I don't understand your question. In the code you posted previously, you are calling startEdit right after cancelEdit so it will certainly continue editing.