javascript Kendo Grid:触发更新点击回车键进行弹出编辑

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15026920/
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-26 23:12:31  来源:igfitidea点击:

Kendo Grid: Trigger Update click on enter key press for popup editing

javascriptkendo-uikendo-grid

提问by bflemi3

I'm using the Kendo UI Grid with popup editing. By default, when the user is editing a field in the popup editor and hits the enter key the data is rendered to the grid (behind the popup editor) but the popup stays visible and the save event is not fired until you click the 'Update' button.

我正在使用带有弹出式编辑功能的 Kendo UI Grid。默认情况下,当用户在弹出编辑器中编辑字段并按下 Enter 键时,数据将呈现到网格(在弹出编辑器后面),但弹出窗口保持可见,并且在单击“更新”之前不会触发保存事件' 按钮。

I'm trying to change that functionality so that when a user hits enter while editing a field it would trigger the 'Update' button click - meaning it would render the data to the grid, fire the save event and close the popup editor.

我正在尝试更改该功能,以便当用户在编辑字段时按 Enter 键时,它会触发“更新”按钮单击 - 这意味着它将数据呈现到网格,触发保存事件并关闭弹出编辑器。

My current attempt will just close the popup editor but does not fire the save event and undoes the changes made to any fields for the selected row. Almost like the cancel button was triggered instead.

我当前的尝试只会关闭弹出编辑器,但不会触发保存事件并撤消对所选行的任何字段所做的更改。几乎就像取消按钮被触发一样。

options.edit = function (e) {
    $('.k-edit-field .k-input').on('keypress', function (e) {
        utils.onEnter(e, function () {
            $('.k-grid-update').trigger('click');
        });
    });
};

How can I trigger the 'Update' button click, or at least simulate what it does?

如何触发“更新”按钮点击,或者至少模拟它的作用?

采纳答案by bflemi3

I wasn't able to find a kendo method to cause the changed fields to become dirty and then be saved, so I used a little jQuery and just shifted the focus to the update button then triggered the click event. Works as expected...

我无法找到一种剑道方法来导致更改的字段变脏然后保存,所以我使用了一个小 jQuery 并将焦点转移到更新按钮然后触发点击事件。按预期工作...

options.edit = function (e) {
    $('.k-edit-field .k-input').on('keypress', function (e) {
        utils.onEnter(e, function () {
            $('.k-grid-update').focus().trigger('click');

        });
    });
};

回答by Vladimir Iliev

I would suggest to use the saveRow methodwhich will save the current data and close the PopUp editor.

我建议使用saveRow 方法,该方法将保存当前数据并关闭 PopUp 编辑器。

e.g.:

例如:

$("#grid").data("kendoGrid").saveRow();