【发布时间】:2014-05-07 17:31:08
【问题描述】:
我有一个可选择、可导航和可编辑的网格。在单元格中输入值后,我必须更改更新单元格下的单元格中的值。要显示两个单元格的更新值,我必须刷新网格。当我这样做时,编辑的单元格失去焦点。我找到了一种在保存事件期间重新聚焦最后编辑的单元格的方法:
save: function (e) {
var focusedCellIndex = this.current()[0].cellIndex; //gets the cell index of the currently focused cell
//...some dataItem saving (dataItem.set()) logic...
this.refresh(); //refreshing the grid instance
setTimeout(function () { //refocusing the cell
return function () {
var focusedCell = $("#grid tr[data-uid='" + dataItem.uid + "'] td:nth-child(" + (focusedCellIndex + 1) + ")");
$('#grid').data('kendoGrid').editCell(focusedCell);
}
}(), 200);
}
问题是这是第一次工作,但如果我再次尝试重新编辑同一个单元格,单元格就会失去焦点。当我尝试调试时,似乎this.current()[0].cellIndex 在第二次尝试中返回 0,并且由于该单元格聚焦不再起作用。
有谁知道为什么this.current() 第一次工作,而不是第二次工作?还有其他方法可以重新聚焦单元格吗?
【问题讨论】:
标签: javascript jquery kendo-ui kendo-grid