The datagrid panel must have a 'tabindex' attribute defined otherwise it can not get focus. Listening to the 'blur' event to end editing a row is not a good solution. An alternative way to solve this issue is to handle the 'mousedown' event on the document.
$(function(){
var curr = null;
$(document).bind('mousedown',function(e){
var v = $(e.target).closest('div.datagrid-view');
if (v.length){
var dg = v.children('table');
if (!curr){
curr = dg;
} else if (dg[0] != curr[0]){
endEditing(curr);
curr = dg;
}
} else {
endEditing(curr);
curr = null;
}
});
function endEditing(dg){
if (!$(dg).length){return}
var opts = dg.datagrid('options');
opts.finder.getTr(dg[0], null, 'editing').each(function(){
var index = parseInt($(this).attr('datagrid-row-index'));
dg.datagrid('endEdit', index);
});
}
})