PDA

View Full Version : RowEditor - Lost array data when closing tab



silve69
4 Sep 2009, 7:37 AM
Hello friends,

Again with a RowEditor question... thanks in advanced.
I have a tabpanel in the center region with dynamic added closable panels, inside one of then I have a grid with RowEditor.


var grid_columns = new Ext.grid.ColumnModel([
...
{header:"Gender", dataIndex:'gender', width:70, editor:{ xtype:'combo', store:gender_store, mode:'Local', triggerAction:'all' }},
...


And the store:


gender_store= new Ext.data.ArrayStore({
idIndex: 0,
fields: ['value','name'],
data: [['F','Female'],['M','Male']]
});


My problem:
The roweditor is working fine, but when I close the panel (pressing the close button) and re-open it and I tryed to edit a row I'm receiving the follow error:
this.store is null
In the ext-all-debug.js (line 54846), corresponding a the follow code:
if(this.store.getCount() > 0){\n

Maybe the data array is destroyed when the panel is closed, but I don't know why because the property autoDestroy is false.

Best regards,
Silver

4 Sep 2009, 7:41 AM
OK, are you re-instantiating everything all over again? Closing a tab, by default, destroys the component!

silve69
4 Sep 2009, 8:14 AM
I created a xtype with a grid extension... and when I re-open the gridpanel the xtype is loaded... this is re-instantiating everything again??

myGrid.js


Ext.ns('App', 'App.myApp');

var editor = new Ext.ux.grid.RowEditor({
saveText: 'Guardar',
cancelText: 'Cancelar',
listeners: {
validateedit : function(roweditor, changes, record, rowindex) {
... here validate the changes and update MySQL database
}
}
});

App.myApp.myGrid = Ext.extend(Ext.grid.GridPanel, {
plugins: [editor],
viewConfig : { forceFit: true },
layout: 'fit',
colModel: grid_columns,
store: grid_store,

initComponent : function() {
this.on ({
afterlayout:{scope:this, single:true, fn:function() {
this.store.load();
}}
});

// super
App.myApp.myGrid.superclass.initComponent.call(this);
}
});
Ext.reg('myGrid', App.myApp.myGrid);


grid_store:


var grid_store = new Ext.data.JsonStore({
idProperty:'iduser',
root:'results',
baseParams:{ ... params here ... },
remoteSort:true,
url: '... url here ...',
fields: grid_fields
});


For re-open the tab I'm using:


west.on ('clickMenu', function(itemMenu) {
idSelected = itemMenu.id;
var tab;
var tp = Ext.getCmp('tabpanel');
if (!(tab = tp.findById(idSelected)))
var tab = tp.add({
id: idSelected,
xtype: 'myGrid',
title: itemMenu.text,
iconCls: 'grid_icon'
});
tp.setActiveTab(tab);
});

The tab is openning correctly and the grid content too... the problem is with the store of combobox in the row editor.

What is wrong??
Thanksssssssssss!!!!

4 Sep 2009, 8:22 AM
Actually, you need to instantiate a new instance of store for *each* instance of Grid.

When the grid is destroyed, so are the store's contents.

silve69
4 Sep 2009, 8:34 AM
Thanks jgarcia,

But... where I need to do that? here?



west.on ('clickMenu', function(itemMenu) {
idSelected = itemMenu.id;
var tab;
var tp = Ext.getCmp('tabpanel');
if (!(tab = tp.findById(idSelected)))
var tab = tp.add({
id: idSelected,
xtype: 'myGrid',
title: itemMenu.text,
iconCls: 'grid_icon',
<<<< ------ here??
});
tp.setActiveTab(tab);
});


Sorry fo the time...
Regards!!!

4 Sep 2009, 8:39 AM
either specify a store <<<< ------ here?? or you can do it in the init component

4 Sep 2009, 8:39 AM
By the way, the editor, as you have things setup, can only be used by the latest instance of your grid.

silve69
4 Sep 2009, 9:25 AM
I moved the store and column declaration to inside initComponent but, anyway I'm receiving the same error "this.store is null", ...I'm loosing the data in some place.

silve69
4 Sep 2009, 4:26 PM
Hello friends,

Sorry the insistence but I lost all the day trying differents options and can't solve my problem.
For some raison, when I close and re-open a grid the RowEditor store is destroyed... and I need to setup correctly the RowEditor for avoiding that.
What is wrong in the previous code? How setup correctly the RowEditor to keep data.

Thanks a lot,
Silver