This is a migrated thread and some comments may be shown as answers.

addRow via jQuery automatically going to 2nd column

2 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 07 Feb 2014, 04:19 PM
I have a batch editing grid where the user can add a new row either by clicking the Add button or tabbing off of the last editable column. The Add button works as intended...it adds a new row at the bottom of the grid and puts the keyboard focus in the first column of the new row.

The problem I am having is calling addRow programatically. It creates the new row at the bottom of the grid, but it automatically puts the keyboard focus in the second column of the new row. I want it to behave the same way as pressing the Add button. Here is the script that catches my keypress [TAB], and determines if it is the last row and last column (in my case it's column index 6). 

function onDataBound(e) {
               var grid = $("#VINGrid").data("kendoGrid");
 
               $(grid.tbody).on("keydown", "td", function (e) {
                 
 
                 if (e.keyCode == 9)
                 {
                       var row = $(this).closest("tr");
                       var rowIdx = $("tr", grid.tbody).index(row);
                       var colIdx = $("td", row).index(this);
 
                       var count = grid.dataSource.total();
 
                       if(rowIdx == count-1 && colIdx == 6)
                       {
                           grid.addRow();
                       }
                   }
               });
           }

Any idea why my script is automatically moving it to the second column? 

Thanks,
Jason

2 Answers, 1 is accepted

Sort by
0
Jason
Top achievements
Rank 1
answered on 10 Feb 2014, 07:23 PM
I figured out my problem...

I had to add:

e.StopImmediatePropagation();
e.preventDefault(); 

...right above the grid.addRow();




0
Dimiter Madjarov
Telerik team
answered on 11 Feb 2014, 08:52 AM
Hi Jason,


Thank you for the update. Let us know if further Kendo UI related problems arise.

Have a great day!

Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Jason
Top achievements
Rank 1
Answers by
Jason
Top achievements
Rank 1
Dimiter Madjarov
Telerik team
Share this question
or