EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: chrwei on March 24, 2015, 02:44:42 PM



Title: numberbox editor in grid, limitations?
Post by: chrwei 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);
}
});


Title: Re: numberbox editor in grid, limitations?
Post by: stworthy 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


Title: Re: numberbox editor in grid, limitations?
Post by: chrwei 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.


Title: Re: numberbox editor in grid, limitations?
Post by: chrwei 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();
}
}