How can I make the grid save when the enter key is pressed? I have tried binding the keycode in the edit handler and that doesn't work.
I have added a kendoNumericTextBox editor for the cell and binded the change event and keydown event to the input. When I edit a cell and then press enter, the keydown event will been fired but the oldValue and newValue are always the same. It seems like the data source for the grid has been changed.
My code as below:
grid.tbody.on(
"change"
,
"input.txtTimeAllocation"
,
function
(e) {
e.preventDefault();
var
row = $(e.target).closest(
"tr"
);
var
cell = $(e.target).closest(
"td"
);
var
colIndex = cell.index();
var
dataItem = grid.dataItem(row);
var
oldValue = dataItem.TimeAllocation[colIndex - 5].Hour;
var
newValue = Number(
this
.value);
if
(oldValue != newValue) {
//save the change
window.alert(
"Hours changed"
);
}
}).on(
"keydown"
,
"input.txtTimeAllocation"
,
function
(e) {
if
(e.keyCode === kendo.keys.ENTER) {
e.preventDefault();
var
row = $(e.target).closest(
"tr"
);
var
cell = $(e.target).closest(
"td"
);
var
colIndex = cell.index();
var
dataItem = grid.dataItem(row);
var
oldValue = dataItem.TimeAllocation[colIndex - 5].Hour;
var
newValue = Number(
this
.value);
if
(oldValue != newValue) {
//save the change
window.alert(
"Hours changed"
);
}
}
});