Kendo grid - get current edit line

How to get the current line that has been edited, even if it is not selected? I have a Kendo grid with batch which is navigatable . My goal is to manually edit the data in a column using the dataItem.set() method. However, when you add a row, it is not automatically selected. Therefore, vm.testGrid.dataItem(vm.testGrid.select()) cannot be used.

vm.testGrid.dataSource.get(e.model.get("Id")) gets the new row added, but if several rows were added before saving, it will always have the first row added ("Id" is set to auto increment and automatically created by the database server, so all newly created rows will first have 0 before saving).

 vm.onEdit = function (e) { $('input.k-input.k-textbox').blur(function (f) { //var data = vm.testGrid.dataItem(vm.testGrid.select()); var data = vm.testGrid.dataSource.get(e.model.get("Id")); // will always get the firstly added row data.set("LookupCol", "1000"); } }); 

Is there a better solution for getting the line that was currently being edited? Or is there a better way to edit the current line?

+6
source share
2 answers

The following will give you the data item associated with the current cell:

 var dataItem = grid.dataItem(grid.current().closest("tr")); // You can then set properties as you want. dataItem.set("field1", "foo"); dataItem.set("field2", "bar"); 
+3
source

I used the function nearest () jQuery:

 vm.onEdit = function (e) { $('input.k-input.k-textbox').blur(function (f) { var data = vm.testGrid.dataItem($(e.container).closest("tr")); data.set("LookupCol", "1000"); } }); 
+2
source

Source: https://habr.com/ru/post/981574/


All Articles