简体   繁体   English

剑道网格 - 获取当前编辑行

[英]Kendo grid - get current editing row

How do you get the current row that's been edited even when it's not selected?即使未选择,您如何获取已编辑的当前行? I have a batch enabled Kendo grid that is navigatable .我有一个可navigatablebatch启用的剑道网格。 My goal is to manually edit data in a column using the dataItem.set() method.我的目标是使用dataItem.set()方法手动编辑列中的dataItem.set() However, when you add a row it does not get selected automatically.但是,当您添加一行时,它不会自动被选中。 Hence, vm.testGrid.dataItem(vm.testGrid.select()) cannot be used.因此,不能使用vm.testGrid.dataItem(vm.testGrid.select())

vm.testGrid.dataSource.get(e.model.get("Id")) gets the newly added row, but if multiple rows were added before saving, it will always get the first added row ("Id" is set to auto increment and is automatically generated by the database server, therefore all newly created rows will initially have 0 before saving). vm.testGrid.dataSource.get(e.model.get("Id"))获取新添加的行,但是如果在保存前添加了多行,它总是会获取第一个添加的行(“Id”设置为自动增量并由数据库服务器自动生成,因此所有新创建的行在保存之前最初都为 0)。

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 to get the row that's been currently edited?是否有更好的解决方案来获取当前已编辑的行? Or is there a better way to edit the current row?或者有没有更好的方法来编辑当前行?

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");

I used the JQuery closest() function:我使用了 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");
    }
});

You can also write an extension for the grid, eg like this您还可以为网格编写扩展,例如像这样

// extend the grid
kendo.ui.Grid.fn.getCurrentDataItem = function() {
  var that = this, current = that.current(), dataItem = null;        
  if (current) {
    dataItem = that.dataItem(current.closest('tr'));
  }        
  return dataItem;
}

JSFiddle example JSFiddle 示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM