3

I tried using various code snippets for implementing this particular functionality of creating a new row when you press enter key WHILE YOU ARE EDITING in a particular cell.

`$(document).on('keypress','body',function(event){
    var keycode = (event.keyCode ? event.keyCode : event.which);
  if(keycode == '13'){
    grid.addRow();

  } 
});​

The above code worked when you simply press enter key, but when you're editing a cell and pressing enter key, it did not create a new row.

I want to create a new row when you press enter key while editing a particular cell.

It would be really great if someone can help me regarding this.

Thanks in advance. Here's the js fiddle.

In short:- If i am editing in a particular cell, when i press the enter key, it should create a new row!

https://jsfiddle.net/aravind_93/c1f3t6yo/

SE_User
  • 370
  • 4
  • 14
  • Did you try to add an event listener on the capturing phase? `document.addEventListener('keypress', function(evt){...}, true);` – Prusse Oct 22 '15 at 14:33
  • Sorry. I did not notice that you did setup a fiddle. Edited yuor fiddle to use capturing https://jsfiddle.net/c1f3t6yo/1/ you could check [this answer](http://stackoverflow.com/a/17249184/783219). – Prusse Oct 22 '15 at 14:44
  • Hi Prusse, No I didn't try that, but it worked when I changed the key press to key up! – SE_User Oct 23 '15 at 15:45

1 Answers1

3

It worked when I replaced "body" with "#stocks_tbl" and "keypress" with "keyup"!

$(document).on('keyup','#stocks_tbl',function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){

    var grid = $("#stocks_tbl").data("kendoGrid");
    grid.addRow();                        
} 
});

Link to updated JS FIDDLE

' #Kendo UI '

SE_User
  • 370
  • 4
  • 14