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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28159289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 08:30:35  来源:igfitidea点击:

Kendo grid - get current editing row

javascriptjqueryangularjskendo-gridkendo-datasource

提问by SharkTiles

How do you get the current row that's been edited even when it's not selected? I have a batchenabled Kendo grid that is navigatable. My goal is to manually edit data in a column using the dataItem.set()method. However, when you add a row it does not get selected automatically. Hence, vm.testGrid.dataItem(vm.testGrid.select())cannot be used.

即使未选择,您如何获取已编辑的当前行?我有一个batch启用的剑道网格是navigatable. 我的目标是使用该dataItem.set()方法手动编辑列中的数据。但是,当您添加一行时,它不会自动被选中。因此,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?

是否有更好的解决方案来获取当前已编辑的行?或者有没有更好的方法来编辑当前行?

回答by moomoo

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

回答by SharkTiles

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