EasyUI Forum
November 05, 2025, 03:41:56 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Datagrid end edit on datagrid loose focus  (Read 9743 times)
devnull
Sr. Member
****
Posts: 431


View Profile
« on: November 17, 2014, 04:32:49 PM »

How can I end cell / row editing when the datagrid looses focus to another element on the page ?

I have tried several onblur() methods but none of them fire.

Thanks

Logged

-- Licensed User --
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: November 17, 2014, 06:24:23 PM »

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.
Code:
$(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);
});
}
})
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!