PDA

View Full Version : [UNKNOWN][3.??] roweditor's record object empty



realjax
23 Dec 2009, 4:22 AM
Roweditors record property is undefined on first edit. Next edits are ok.

Condor
23 Dec 2009, 4:31 AM
Can you post an example?

realjax
23 Dec 2009, 5:01 AM
editor : new Ext.ux.grid.RowEditor({

.....

listeners: {
/**
* @event beforeedit
* Fired before the row editor is activated.
* If the listener returns <tt>false</tt> the editor will not be activated.
* @param {Ext.ux.grid.RowEditor} roweditor This object
* @param {Number} rowIndex The rowIndex of the row just edited
*/
beforeedit:function(roweditor, rowIndex){
console.log(roweditor.record)
}
}
}

.............
Firefox's console will report 'undefined' on first edit.


Edit: hmm, Looking back I see my initial post is not a very descriptive one.. :-)
please let me know if you have enough info now.

Condor
23 Dec 2009, 5:20 AM
That is because record and rowIndex are set AFTER beforeedit is called. This means that the record will be set in the second time beforeedit call, but it will be the previous record!

Suggested patch:

Ext.override(Ext.ux.grid.RowEditor, {
startEditing: function(rowIndex, doFocus){
if(this.editing && this.isDirty()){
this.showTooltip(this.commitChangesText);
return;
}
var record;
if(Ext.isObject(rowIndex)){
rowIndex = this.grid.getStore().indexOf(record = rowIndex);
}else{
record = this.grid.getStore().getAt(rowIndex);
}
this.record = record;
this.rowIndex = rowIndex;
if(this.fireEvent('beforeedit', this, rowIndex) !== false){
this.editing = true;
var g = this.grid, view = g.getView(),
row = view.getRow(rowIndex);
//record = g.store.getAt(rowIndex);
//this.record = record;
//this.rowIndex = rowIndex;
this.values = {};
if(!this.rendered){
this.render(view.getEditorParent());
}
var w = Ext.fly(row).getWidth();
this.setSize(w);
if(!this.initialized){
this.initFields();
}
var cm = g.getColumnModel(), fields = this.items.items, f, val;
for(var i = 0, len = cm.getColumnCount(); i < len; i++){
val = this.preEditValue(record, cm.getDataIndex(i));
f = fields[i];
f.setValue(val);
this.values[f.id] = Ext.isEmpty(val) ? '' : val;
}
this.verifyLayout(true);
if(!this.isVisible()){
this.setPagePosition(Ext.fly(row).getXY());
} else{
this.el.setXY(Ext.fly(row).getXY(), {duration:0.15});
}
if(!this.isVisible()){
this.show().doLayout();
}
if(doFocus !== false){
this.doFocus.defer(this.focusDelay, this);
}
}
}
});