9

在编辑我的网格时,如果我在网格外单击,我正在编辑的框仍然是可编辑的。当它失去焦点时,如何让编辑的单元格“完成”编辑?

4

3 回答 3

15

以下代码将保存当前编辑。

Slick.GlobalEditorLock.commitCurrentEdit();

您需要将其放置在您认为应该触发保存的事件处理程序中。例如,如果您使用的是示例文本编辑器插件,我相信editor-textCSS 类会添加到您在编辑单元格时创建的输入字段中,所以这样的事情应该可以工作:

$('#myGrid').on('blur', 'input.editor-text', function() {
    Slick.GlobalEditorLock.commitCurrentEdit();
});
于 2013-03-20T01:09:21.663 回答
6

我发现我需要在超时中包装 clav 的处理程序:

$("#myGrid").on('blur', 'input.editor-text', function() {

    window.setTimeout(function() {

        if (Slick.GlobalEditorLock.isActive())
            Slick.GlobalEditorLock.commitCurrentEdit();

    });

});

以避免出现以下错误:

Uncaught NotFoundError: An attempt was made to reference a Node in a context where it does not exist. 

使用键盘导航时。据推测,新的模糊处理程序在 SlickGrid 可以自己处理之前触发,这会导致问题。

于 2013-08-12T22:11:02.120 回答
5

Unfortunately, probably due to differences in event processing, Grame's version breaks keyboard navigation in chrome. To fix this, I added another check to only commit the edit, if the newly focused element is not another editor element within the grid (as the result of keyboard navigation):

            $('#grid').on('blur.editorFocusLost', 'input.editor-text', function() {
                window.setTimeout(function() {
                    var focusedEditor = $("#grid :focus");
                    if (focusedEditor.length == 0 && Slick.GlobalEditorLock.isActive()) {
                        Slick.GlobalEditorLock.commitCurrentEdit();
                    }
                });
            });

This seems to work in current versions of firefox, chrome and ie.

于 2014-08-14T13:50:29.373 回答