PDA

View Full Version : [solved] RowEditor suviving a reconfigure()?



jasonb885
24 May 2009, 1:48 PM
Anyone have any thoughts on how best to allow Ext.ux.RowEditor to survive a grid reconfigure?

Here's the additional code necessary to resolve this:



// Ensure editor knows about changed columns
if(this.editor.initialized) {
this.editor.items.each(function(i) {
i.destroy();
});
this.editor.items.clear();
}
this.editor.initialized = false;


...

At the moment, I have in initComponent of extended Ext.grid.GridPanel:



this.getStore().on('load', function(store) {
// Ensure editor knows about changed columns
this.editor.initialized = false;
}, this);


Which allows it to recognize the new columns. However, inside RowEditor, items isn't cleaned up in whatever way would be most appropriate, causing it to grow with each reconfigure call. It seems items are added during the initFields call, which ordinarily would be called only once, but I am overriding above.



initFields: function(){
var cm = this.grid.getColumnModel(), pm = Ext.layout.ContainerLayout.prototype.parseMargins;
for(var i = 0, len = cm.getColumnCount(); i < len; i++){
var c = cm.getColumnAt(i);
var ed = c.getEditor();
if(!ed){
ed = c.displayEditor || new Ext.form.DisplayField();
}
if(i == 0){
ed.margins = pm('0 1 2 1');
} else if(i == len - 1){
ed.margins = pm('0 0 2 1');
} else{
ed.margins = pm('0 1 2');
}
ed.setWidth(cm.getColumnWidth(i));
ed.column = c;
if(ed.ownerCt != this){
ed.on('focus', this.ensureVisible, this);
ed.on('specialkey', this.onKey, this);
}
this.insert(i, ed);
}
this.initialized = true;
// Grows forever due to metagrid
console.log(this.items);
},


Just calling this.items.clear() isn't enough. It doesn't survive a reconfigure and startEditing, producing the following when clicking in an editor form field:



this.config[colIndex] is undefined
[Break on this error] return this.config[colIndex].hidden;


Seems to flow from



ensureVisible: function(editor){
if(this.isVisible()){
this.grid.getView().ensureVisible(this.rowIndex, this.grid.colModel.getIndexById(editor.column.id), true);
}
},


At that point, I'm lost, since it seems to have the current colModel after a reconfigure, but something is quite wrong.

(Would be useful with, for example, Ext.ux.grid.MetaGrid.)

Although those lines, what would I need to change to allow RowEditor to respond to a destroy() call?

Thanks.

Stju
29 Aug 2009, 7:51 AM
Hi!
Can You post the actula solution?
I went into serious trouble and completely lost now :-? ...
I have MetaGrid and after reconfigure, RowEditor keeps all the information from previous configuration no mather what I am doing...

Any help would be greately appreciated!
Stju

jasonb885
29 Aug 2009, 8:22 AM
Hi!
Can You post the actula solution?
I went into serious trouble and completely lost now :-? ...
I have MetaGrid and after reconfigure, RowEditor keeps all the information from previous configuration no mather what I am doing...

Any help would be greately appreciated!
Stju

No idea. I gave up on it. It's not worth the hassle. I always preferred a panel with a form for editing anyway.

Stju
29 Aug 2009, 9:46 AM
Fianlly, I found a solution!
Probably this is a bug in RowEditor, but changing line 241 in RowEditor.js helps , and now it works like a charm :)

original:


initFields: function(){
var cm = this.grid.getColumnModel(), pm = Ext.layout.ContainerLayout.prototype.parseMargins;
this.removeAll(false);
changed to:


initFields: function(){
var cm = this.grid.getColumnModel(), pm = Ext.layout.ContainerLayout.prototype.parseMargins;
this.removeAll(true);
Other thing to consider is to put yourRowEditor.stopEditing() in store metachange event, and after that, create new RecordModel from received data!

Hope this would be helpful for someone and saves some time :)
Stju