我有一个可选择、可导航、可编辑的网格。在我输入单元格中的值之后,我必须更改更新单元格下方的单元格中的值。为了显示两个单元格的更新值,我必须刷新网格。当我这样做时,编辑的单元格失去焦点。我找到了一种在保存事件期间重新聚焦上次编辑的单元格的方法:
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()
只有第一次有效而第二次无效?还有其他重新聚焦单元格的方法吗?
_lastFocusedCellIndex
现在一直在工作。但是,例如,如果我编辑第3行的第10个单元格,它将被重新聚焦;如果我再次编辑它,焦点将转移到第1行的第10个单元格。所以,我只需要获取最后一个聚焦单元格所在行的行索引(或uid)。我尝试使用您版本的kendo.ui.Grid.fn.current
扩展this._lastFocusedCell = $(element);
,然后获取单元格的dataItem,但第二次返回网格的第一个dataItem。 - tstancin