EasyUI Forum
May 04, 2024, 09:46: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: numberbox editor in grid, limitations?  (Read 7103 times)
chrwei
Full Member
***
Posts: 219


View Profile Email
« on: March 24, 2015, 02:44:42 PM »

trying to add some "friendliness" to a grid, where when clicking a row the clicked cell gets focus, and also when pressing enter it ends editing.  code excerpt below.

This works for editor type=text, but does not for numberbox.  the box does not get focus, and keydown event does not register at all, no output on console for any key press on numberboxs.  is there a work around?

Code:
$("#data").datagrid({
onBeginEdit: function(rowIndex, rowData) {
$.each($('#data').datagrid('getEditors', rowIndex), function(i, o) {
$(o.target).on('keydown', function(e){
console.log(e.keyCode);
switch(e.keyCode) {
case 13: //
$('#data').datagrid('endEdit', rowIndex);
}
});
});
},
onClickCell: function(i,f,v) {
setTimeout(function() {
$($('#data').datagrid('getEditor', {index:i,field:f}).target).focus();
}, 100);
}
});
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: March 24, 2015, 05:58:44 PM »

Please refer to this example http://www.jeasyui.com/demo/main/index.php?plugin=DataGrid&theme=default&dir=ltr&pitem=Row%20Editing%20in%20DataGrid
Logged
chrwei
Full Member
***
Posts: 219


View Profile Email
« Reply #2 on: March 25, 2015, 05:54:28 AM »

that's odd, I was basing it off the row editing demo, but yesterday it used onClickRow, I even copy/pasted that function.
Logged
chrwei
Full Member
***
Posts: 219


View Profile Email
« Reply #3 on: March 25, 2015, 06:10:19 AM »

so textbox('textbox') is the trick.  I was able to add the keydown using this in the onClickCell.

Code:
			$.each($('#dg').datagrid('getEditors', index), function(i, o) { 
($(o.target).data('textbox') ? $(o.target).textbox('textbox').on('keydown', addKeyHandle) : $(o.target).on('keydown', addKeyHandle));
});
and this is the addKeyHandle function
Code:
function addKeyHandle(e){
switch(e.keyCode) {
case 13: //
endEditing();
}
}


« Last Edit: March 25, 2015, 06:12:44 AM by chrwei » 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!