Bind the 'keydown' event on the editing box. When pressing the ESC key, cancel the current editing action. Please refer to the following code.
$('#dg').datagrid({
onBeginEdit:function(index,row){
var dg = $(this);
var ed = dg.datagrid('getEditors',index)[0];
if (!ed){return;}
var t = $(ed.target);
if (t.hasClass('textbox-f')){
t = t.textbox('textbox');
}
t.bind('keydown', function(e){
if (e.keyCode == 13){
dg.datagrid('endEdit', index);
} else if (e.keyCode == 27){
dg.datagrid('cancelEdit', index);
}
})
}
}).datagrid('enableCellEditing');