-
14 Sep 2006 6:43 AM #1
getDataModel().removeRows(0) loses selection
getDataModel().removeRows(0) loses selection
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.
-
14 Sep 2006 9:40 AM #2
Seems to work...
Seems to work...
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.
[img][/img]Code: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'; } } ....
-
14 Sep 2006 11:25 AM #3
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:
Thanks for the help next2you. Anyone would can locate that bug in the miles of grid code should be working on the project!Code: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; } };
Jack
-
6 Jun 2007 9:17 AM #4
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).
-
6 Jun 2007 6:41 PM #5
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?
-
6 Jun 2007 8:55 PM #6
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.
Similar Threads
-
Grid Single Selection only?
By steven in forum Ext 2.x: Help & DiscussionReplies: 5Last Post: 14 Apr 2011, 5:40 AM -
Correct way to cancel node selection?
By jmakeig in forum Ext 1.x: Help & DiscussionReplies: 1Last Post: 15 Jan 2007, 7:42 AM -
How to listen to grid selection changes?
By gcsolaroli in forum Ext 1.x: Help & DiscussionReplies: 1Last Post: 14 Dec 2006, 12:19 AM -
Highlight Selection in PropsGrid Example
By dmayer in forum Ext 1.x: Help & DiscussionReplies: 3Last Post: 8 Nov 2006, 5:48 PM


Reply With Quote