PDA

View Full Version : getDataModel().removeRows(0) loses selection



next2you
14 Sep 2006, 6:43 AM
Hi,

when I call (in the Example code), this.grid.getDataModel().removeRows(0) with a hyperlink in the page, my selected row is lost. (e.g. if the third row is selected)

Firefox 1.5.0.7 on OSX.

next2you
14 Sep 2006, 9:40 AM
Apparently function updateRowIndexes resets the rows to the class ygrid-row or ygrid-row-alt class, fix would be to check for the class ygrid-row-selected and leave this row untouched.



updateRowIndexes : function(firstRow, lastRow){
.....
if (nodes[rowIndex].className.indexOf("ygrid-row-selected") == -1) {
if(stripeRows && (rowIndex+1) % 2 == 0){
nodes[rowIndex].className = 'ygrid-row ygrid-row-alt';
} else{
nodes[rowIndex].className = 'ygrid-row';
}
}
....

jack.slocum
14 Sep 2006, 11:25 AM
Thanks for tracking that down next2you. That's exactly the problem. The only problem with that patch you posted is if they deselect a selected row after a delete it will be 50/50 to have the wrong alt/non-alt class. It also mixes selection logic with the view logic. If I implement a different selection model that uses a different css class for example, that code would break.

I try to keep that block of code as fast and minimal as possible since it could iterating 500 rows or whatever. That's why I assign directly to the className. This bug is a perfect example of why overwriting the className is always a bad idea. New code broke unrelated existing code. addClass, removeClass and replaceClass are much better solutions but all 3 are too slow.

Here's a slightly altered patch until the next release:



YAHOO.ext.grid.GridView.prototype.updateRowIndexes = function(firstRow, lastRow){
var stripeRows = this.grid.stripeRows;
var bt = this.getBodyTable();
var nodes = bt.childNodes;
firstRow = firstRow || 0;
lastRow = lastRow || nodes.length-1;
var re = /^(?:ygrid-row ygrid-row-alt|ygrid-row)/;
for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
var node = nodes[rowIndex];
if(stripeRows && (rowIndex+1) % 2 == 0){
node.className = node.className.replace(re, 'ygrid-row ygrid-row-alt');
}else{
node.className = node.className.replace(re, 'ygrid-row');
}
node.rowIndex = rowIndex;
}
};


Thanks for the help next2you. Anyone would can locate that bug in the miles of grid code should be working on the project!

Jack

dnixon
6 Jun 2007, 9:17 AM
I am seeing a similar problem in 1.1beta1 (and possibly earlier releases).
I have several tabs with a grid in each. If I select a row in tab A, then go to tab B and then back to A, the selection is still there when tab A is activated again but shortly thereafter the selection is removed (less than a second).

jack.slocum
6 Jun 2007, 6:41 PM
There's nothing in Ext 1.1 doing that. It has no knowledge of changing tabs. Is there anything else going on in the page?

dnixon
6 Jun 2007, 8:55 PM
I do refresh the data using ds.load() each time I activate a tab, although in the case I'm seeing there is no new data, just the same data being returned again from the server. Can/should the data store or individual records be configured/modified to figure out whether or not their data has changed and update the grid or not as appropriate? Any pointers as to how? If not then I guess I need to note the current selection before the update, and restore it afterwards if possible.