PDA

View Full Version : [OPEN-1243] grid.GroupingView rowupdated event with 1 row



tonedeaf
17 Feb 2010, 11:12 AM
GridView Class API Event:

rowupdated : ( Ext.grid.GridView view, Number firstRow, Ext.data.record record )
Internal UI Event. Fired after a row has been updated.

Listeners will be called with the following arguments:
* view : Ext.grid.GridView
* firstRow : Number
The index of the row updated.
* record : Ext.data.record
The Record backing the row updated.

When a rowupdated event is fired in a GroupingView containing just one row, the firstRow and record parameters are undefined.

Noticed that the GroupingView handles a view with a single row in a "special" way:
http://www.extjs.com/deploy/ext-3.1.1/docs/source/GroupingView.html#cls-Ext.grid.GroupingView


// private
refreshRow : function(record){
if(this.ds.getCount()==1){
this.refresh();
}else{
this.isUpdating = true;
Ext.grid.GroupingView.superclass.refreshRow.apply(this, arguments);
this.isUpdating = false;
}
},

In this case, the rowupdated event will be fired without the arguments (firstRow and record). Why is this?

I can submit a detailed test case if required.

Jamie Avins
17 Feb 2010, 11:15 AM
Go ahead and post a test case so we can add it to our issues list.

tonedeaf
17 Feb 2010, 11:29 AM
I noticed this issue while building a larger application, not sure why anyone hasn't noticed that a grid GroupingView containing just one row doesn't fire a rowupdated event correctly. Maybe I'm missing something obvious.

It'll take me sometime to create a separate test case for this issue, but as I've pointed out the source code line in question, can anyone tell me why a rowrefresh of a GroupingView with only one row is handled in this manner?

Overriding the function with only the else{} condition statements makes the rowupdated event fire with all arguments correctly.

iyerv
30 Apr 2010, 7:13 AM
Am also experiencing the same issue for the "one row" grid. It appears that in refresh() this line:
this.grid.stopEditing(true);
indicated cancel is true and cancelEdit is called instead of completeEdit which retains the original value...

sumit.madan
27 Aug 2010, 3:56 AM
The GroupingGrid class refreshRow() functions calls the following two functions of its parent GridView class:



refreshRow : function(record){
var ds = this.ds, index;
if(Ext.isNumber(record)){
index = record;
record = ds.getAt(index);
if(!record){
return;
}
}else{
index = ds.indexOf(record);
if(index < 0){
return;
}
}
this.insertRows(ds, index, index, true);
this.getRow(index).rowIndex = index;
this.onRemove(ds, record, index+1, true);
this.fireEvent('rowupdated', this, index, record);
},

/**
* Refreshs the grid UI
* @param {Boolean} headersToo (optional) True to also refresh the headers
*/
refresh : function(headersToo){
this.fireEvent('beforerefresh', this);
this.grid.stopEditing(true);

var result = this.renderBody();
this.mainBody.update(result).setWidth(this.getTotalWidth());
if(headersToo === true){
this.updateHeaders();
this.updateHeaderSortState();
}
this.processRows(0, true);
this.layout();
this.applyEmptyText();
this.fireEvent('refresh', this);
},
This is the code in question for GroupingView.refreshRow() function:


refreshRow : function(record){
if(this.ds.getCount()==1){
this.refresh();
}else{
this.isUpdating = true;
Ext.grid.GroupingView.superclass.refreshRow.apply(this, arguments);
this.isUpdating = false;
}
},
When the GroupingView contains only one row, parent class GridView.refresh() is called, else the GridView.refreshRow() is called, why?

I think the if condition is at fault here, the logic should be that the GridView.refreshRow() function should be called whenever there are rows in the view.
In the current code, the rowupdated event is fired with incorrect arguments, if there is just one row in the GroupingView.

The override I use to correct this issue:


/* GroupingView refreshRow even fires incorrectly with only one row
* http://www.sencha.com/forum/showthread.php?92305#post438143
*/
Ext.override(Ext.grid.GroupingView, {
refreshRow : function(record) {
if(this.ds.getCount() < 1) {
this.refresh();
} else {
this.isUpdating = true;
Ext.grid.GroupingView.superclass.refreshRow.apply(this, arguments);
this.isUpdating = false;
}
}
});