Nov 26, 2010, 1:56 PM
[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);
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>