小弟發現造成錯亂是因為自己沒有將view做refresh,應該在新增刪除後執行grid.view.refresh()。
-- 舊文章 --
在ext-js中的Ext.grid.rownumberer()常常會因為store的新增刪除造成數字錯亂,可以在grid中執行新增刪除的地方(如insertRows()/removeRow()),修改成每次執行後都要refresh()即可解決。
不過小弟也不知道這算不算是正解。
將
insertRows : function(dm, firstRow, lastRow, isUpdate){
if(!isUpdate && firstRow === 0 && lastRow >= dm.getCount()-1){
this.refresh();
}else{
if(!isUpdate){
this.fireEvent("beforerowsinserted", this, firstRow, lastRow);
}
var html = this.renderRows(firstRow, lastRow);
var before = this.getRow(firstRow);
if(before){
Ext.DomHelper.insertHtml('beforeBegin', before, html);
}else{
Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
}
if(!isUpdate){
this.fireEvent("rowsinserted", this, firstRow, lastRow);
this.processRows(firstRow);
}
}
this.syncFocusEl(firstRow);
},
改成
insertRows : function(dm, firstRow, lastRow, isUpdate){
if(!(!isUpdate && firstRow === 0 && lastRow >= dm.getCount()-1)) {
if(!isUpdate){
this.fireEvent("beforerowsinserted", this, firstRow, lastRow);
}
var html = this.renderRows(firstRow, lastRow);
var before = this.getRow(firstRow);
if(before){
Ext.DomHelper.insertHtml('beforeBegin', before, html);
}else{
Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
}
if(!isUpdate){
this.fireEvent("rowsinserted", this, firstRow, lastRow);
this.processRows(firstRow);
}
}
this.refresh();
this.syncFocusEl(firstRow);
},

沒有留言:
張貼留言