1. #1
    Ext User
    Join Date
    Mar 2007
    Posts
    6
    Vote Rating
    0
    next2you is on a distinguished road

      0  

    Default 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.

  2. #2
    Ext User
    Join Date
    Mar 2007
    Posts
    6
    Vote Rating
    0
    next2you is on a distinguished road

      0  

    Default 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.

    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';
            		}
    		}
         ....
    [img][/img]

  3. #3
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    6,956
    Vote Rating
    18
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default

    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:

    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;
        }
    };
    Thanks for the help next2you. Anyone would can locate that bug in the miles of grid code should be working on the project!

    Jack

  4. #4
    Ext User
    Join Date
    Mar 2007
    Posts
    102
    Vote Rating
    0
    dnixon is on a distinguished road

      0  

    Default

    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).

  5. #5
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    6,956
    Vote Rating
    18
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default

    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?
    Jack Slocum
    Sencha Co-Founder, Ext JS Founder
    Original author of Ext JS 1, 2 & 3.
    Twitter: @jackslocum

  6. #6
    Ext User
    Join Date
    Mar 2007
    Posts
    102
    Vote Rating
    0
    dnixon is on a distinguished road

      0  

    Default

    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

  1. Grid Single Selection only?
    By steven in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 14 Apr 2011, 5:40 AM
  2. Correct way to cancel node selection?
    By jmakeig in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 15 Jan 2007, 7:42 AM
  3. How to listen to grid selection changes?
    By gcsolaroli in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 14 Dec 2006, 12:19 AM
  4. Highlight Selection in PropsGrid Example
    By dmayer in forum Ext 1.x: Help & Discussion
    Replies: 3
    Last Post: 8 Nov 2006, 5:48 PM

Thread Participants: 2