[1.0] Command listener reports incorrect rowIndex under specific circumstances

  1. #1

    [1.0] Command listener reports incorrect rowIndex under specific circumstances

    Steps to reproduce:

    1) Execute the code below
    2) On 4th row in the GridPanel, click the up command
    3) Click the up command again on the 4th row

    You would see that 3rd row moves up, whereas it should have been 4th row. The bug is in supplying the rowIndex parameter to the listener.

    My temporary workaround is to manually calculate the row index:

    rowIndex = this.store.indexOf(record);

    <%@ Page Language="C#" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
    	protected void Page_Load (object sender, EventArgs e)
    	{
    		List<object> l=new List<object>();
    		l.Add(new { f1 = "1", f2 = "1" });
    		l.Add(new { f1 = "2", f2 = "2" });
    		l.Add(new { f1 = "3", f2 = "3" });
    		l.Add(new { f1 = "4", f2 = "4" });
    
    		this.store.DataSource = l;
    		this.store.DataBind();
    	}
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
    		<ext:ResourceManager runat="server" />
    		
    		<ext:GridPanel runat="server" Width="400" Height="400">
    			<Store>
    				<ext:Store runat="server" ID="store">
    					<Reader>
    						<ext:JsonReader>
    							<Fields>
    								<ext:RecordField Name="f1" />
    								<ext:RecordField Name="f2" />
    							</Fields>
    						</ext:JsonReader>
    					</Reader>
    				</ext:Store>
    			</Store>
    			
    			<ColumnModel runat="server">
    				<Columns>
    					<ext:CommandColumn Width="50">
    						<Commands>
    							<ext:GridCommand Icon="ArrowUp" CommandName="MoveUp" />
    						</Commands>
    					</ext:CommandColumn>
    					<ext:Column DataIndex="f1" Header="f1" />
    					<ext:Column DataIndex="f2" Header="f2" />
    				</Columns>
    			</ColumnModel>
    			
    			<Listeners>
    				<Command Handler="
        var store = this.store;
    
        var deleted = [];
        Ext.each(store.deleted, function(rec) { deleted.push(rec); });
    
        var record = store.getAt(rowIndex);
        store.remove(record);
        store.insert(rowIndex - 1, record);
    
        store.deleted = deleted;
    				" />
    			</Listeners>
    		</ext:GridPanel>
        </div>
        </form>
    </body>
    </html>
  2. #2
    Hi,

    Yes, command always caches record and rowIndex. We will investigate it
    Workaround: add the following line to the end of Command handler
    this.view.refreshRow(rowIndex);
    P.S. Small advice: to copy an array you can use slice method instead Ext.each
    Ext.each(store.deleted, function(rec) { deleted.push(rec); });
    can be replaced by
    var deleted = store.deleted.slice(0);
  3. #3
    Hi,

    Fixed in SVN
  4. #4
    Quote Originally Posted by Vladimir View Post
    Yes, command always caches record and rowIndex.
    Is the command associated with the view row, or the store record??
    If its associated with the record itself, then above statement seems meaningful to me. In any other case (associated with GridPanel or the view), shouldn't the command have been removed when the record was removed from the store, and re-created when its inserted again.

    Thanks for the tip on array copying :)
    I was actually performing additional tasks instead of blank copying, this code was assembled in haste...

    And as always, thanks for the quick fix too!!!
  5. #5
    Hi,

    Command is associated with the record (just we calculated and save record index), now we recalculate record index before event firing
  6. #6
    Quote Originally Posted by Vladimir View Post
    Command is associated with the record (just we calculated and save record index), now we recalculate record index before event firing
    Hmmm... thanks for the explanation...

Similar Threads

  1. Replies: 8
    Last Post: Dec 20, 2017, 1:52 PM
  2. Replies: 1
    Last Post: Apr 11, 2012, 12:39 PM
  3. [CLOSED] Command Listener not fired on IE9
    By ddslogistics in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Mar 05, 2012, 3:07 PM
  4. Replies: 0
    Last Post: May 12, 2011, 5:37 PM
  5. Replies: 6
    Last Post: Feb 22, 2010, 1:18 AM

Posting Permissions