EasyUI Forum
September 19, 2025, 01:26:24 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-cellediting: keyboard navigation [SOLVED]  (Read 14639 times)
korenanzo
Guest
« on: March 11, 2016, 09:18:21 AM »

Hi,

I am using datagrid-cellediting.

I need to navigate across the cells using the arrow (up and down)  keys while in editing mode: is it possible?

How?

Thanks,
RIc

« Last Edit: March 14, 2016, 02:27:10 AM by korenanzo » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: March 11, 2016, 07:44:13 PM »

You can't navigate to other cells by keyboard before finish the editing.
Logged
korenanzo
Guest
« Reply #2 on: March 14, 2016, 01:34:08 AM »

I've already extended the editors (  $.fn.datagrid.defaults.editors.textbox ) for other reasons;
maybe it is possible to call the navHandler functions from inside the keypress events of editors?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: March 14, 2016, 02:13:55 AM »

The alternative solution is to navigate the editing cell up/down by watching the 'keydown' event on the inputing box. Please refer to the code below:
Code:
$('#dg').datagrid({
data: data,
onCellEdit: function(index,field){
var dg = $(this);
var input = dg.datagrid('input', {index:index,field:field});
input.bind('keydown', function(e){
if (e.keyCode == 38 && index>0){ // up
dg.datagrid('endEdit', index);
dg.datagrid('editCell', {
index: index-1,
field: field
});
} else if (e.keyCode == 40 && index<dg.datagrid('getRows').length-1){ // down
dg.datagrid('endEdit', index);
dg.datagrid('editCell', {
index: index+1,
field: field
});
}
})
}
}).datagrid('enableCellEditing');
Logged
korenanzo
Guest
« Reply #4 on: March 14, 2016, 02:26:06 AM »

Yesss!

Got it!

Logged
korenanzo
Guest
« Reply #5 on: March 16, 2016, 03:40:32 AM »

I'd like to manage alse the enter key in this way: in edit cell mode, when you press ENTER ti'd like to end the edit and start the edit in te next (right) cell.

I added this, but id does not work: the End edit is ok, but the next cell is not selected ,nor edited.


Code:
     else if(e.keyCode == 13 ) { 
                        dg.datagrid('endEdit', index);

                        dg.datagrid('gotoCell','right');
                        dg.datagrid('editCell',dg.datagrid('cell'));

                    }
 

Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #6 on: March 16, 2016, 08:25:55 AM »

Please try this code instead.
Code:
else if (e.keyCode == 13){
dg.datagrid('endEdit', index);
dg.datagrid('gotoCell', {index:index,field:field});
dg.datagrid('gotoCell', 'right');
dg.datagrid('editCell',dg.datagrid('cell'));
return false;
}
Logged
korenanzo
Guest
« Reply #7 on: March 16, 2016, 08:33:05 AM »

EXCELLENT ! Cool Cool Cool Cool
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!