Ag Grid禁用按键编辑

时间:2017-07-20 15:30:24

标签: angular ag-grid

在Ag-Grid中如何禁用编辑按键可按键打印的编辑?我只有在调用 api.startEditingCell()时才需要编辑一行。我没有找到Documentation

2 个答案:

答案 0 :(得分:1)

editable列属性可以是布尔值,也可以是函数。

您可以将editable设置为默认情况下返回false的函数,并且在通过某些外部进程/操作启动编辑后为true

答案 1 :(得分:0)

您可以通过suppressKeyboardEvent

取消所有键
const suppressKeyboardEvent = (params: SuppressKeyboardEventParams) => {
    const SuppressKeyWhileNoEdit = [".", "/", "*", "-", "+", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; // disallow numpad keys but still allow numpad control keys

    const alphaKeys = ["KeyA", "KeyB", "KeyC", "KeyD", "KeyE", "KeyF", "KeyG", "KeyH", "KeyI", "KeyJ", "KeyK", "KeyL", "KeyM", "KeyN", "KeyO", "KeyP", "KeyQ", "KeyR", "KeyS", "KeyT", "KeyU", "KeyV", "KeyW", "KeyX", "KeyY", "KeyZ"];
    const digitKeys = ["Digit0", "Digit1", "Digit2", "Digit3", "Digit4", "Digit5", "Digit6", "Digit7", "Digit8", "Digit9"];
    const specialKeys = ["Backquote", "Minus", "Equal", "Backspace", "BracketLeft", "BracketRight", "Semicolon", "Quote", "Backslash", "Comma", "Period", "Slash", "IntlBackslash", "Delete"];

    const SuppressCodeWhileNoEdit = alphaKeys.concat(digitKeys.concat(specialKeys));

    const keyPressKey = params.event.key;
    const keyPressCode = params.event.code;

    return !params.editing && (SuppressCodeWhileNoEdit.includes(keyPressCode) || SuppressKeyWhileNoEdit.includes(keyPressKey));
};