Let me leave my solution here for Google. Tested with version 1.4.4
Basically you need to override editRow
method, but EasyUI seems to be not very well designed and internals are totally undocumented. Also there's a call to hidden focusEditor
function, so I ended up with this code. It triggers saveRow
with <Enter> and allows you to insert line break in multiline editor with <Shift> + <Enter>. I also turned off saving by clicking other row due to many accidental errors.
$.fn.edatagrid.methods.editRow = function(jq, index){
return jq.each(function(){
var dg = $(this);
var opts = $.data(this, 'edatagrid').options;
var editIndex = opts.editIndex;
if (editIndex != index){
// -------------------- ✂ --------------------
// Lost focus
if (editIndex != -1) {
dg.edatagrid('cancelRow');
return;
}
// -------------------- ✂ --------------------
if (dg.datagrid('validateRow', editIndex)){
if (editIndex>=0){
if (opts.onBeforeSave.call(this, editIndex) == false) {
setTimeout(function(){
dg.datagrid('selectRow', editIndex);
},0);
return;
}
}
dg.datagrid('endEdit', editIndex);
dg.datagrid('beginEdit', index);
if (!dg.edatagrid('isEditing', index)){
return;
}
opts.editIndex = index;
// -------------------- ✂ --------------------
// Based on focusEditor() function
var target;
var that = this;
var editor = $(this).datagrid('getEditor', {index:opts.editIndex});
if (editor){
target = editor.target;
} else {
var editors = $(this).datagrid('getEditors', opts.editIndex);
if (editors.length){
target = editors[0].target;
}
}
if (target){
var field = $(target).hasClass('textbox-f') ? $(target).textbox('textbox') : $(target);
field.focus();
field.bind('keydown', function(e) {
if (e.which == 13 && !event.shiftKey) {
$(that).edatagrid('saveRow');
}
});
}
// -------------------- ✂ --------------------
var rows = dg.datagrid('getRows');
opts.onEdit.call(this, index, rows[index]);
} else {
setTimeout(function(){
dg.datagrid('selectRow', editIndex);
}, 0);
}
}
});
};