I have a kendo grid with edit mode set to incell.
What is the most elegant way of programmatically focus a particular cell to force it into an edit mode?
Let's say I have a grid where column 1 and 6 are editable. As soon as user finishes typing something into column 1, I'd like the column 6 textbox to be automatically focused and enabled for editing so that the user doesn't have to manually click on the next editable gridcell for the same row.
This is what I'm doing at the moment:
//Focuses the editable cell at given row/column index.
//Closes the previously editing cell
//EX: setGridFocus(SALE_01_DIV_GRID,0,0) --> Focuses SALE_01_DIV_GRID (0,0)
function setGridFocus(gridID, rowIndex, colIndex)
{
var grid = $('#' + gridID).data('kendoGrid');
grid.closeCell();
setTimeout(function(){
var cell = $('#' + gridID).find('tbody tr:eq('+rowIndex+') td:eq('+colIndex+')');
grid.editCell(cell);
var editTextCell = cell.find("input.k-formatted-value");
editTextCell.focus(function() {
$(this).select().mouseup(function (e) {
e.preventDefault();
$(this).unbind("mouseup");
e.select();
});
});
cell.find("input[type=text]").select();
editTextCell.selectall();
},50);
}
First of all, I'm using setTimeout to implement what is seemingly a trivial function so this doesn't seem like the ideal approach.
Secondly, the above function only works when it feels like it (Only works half of the time from testing. Probably expected from setTimeout function). I feel like this has to do with the order of events called internally in Kendo Grid.
Thirdly, I'd like to block select the text that's inside the cell being focused. editTextCell.selectall(); doesn't work for this purpose.
I'd appreciate any guidance.