vue.js - 如何防止在 ag-grid 中使用自定义 vue 组件验证错误时关闭单元格编辑模式

标签 vue.js ag-grid

我已经成功地将我自己的组件呈现为 cellEditor,并且在休假时我希望它尝试验证值并在失败时阻止关闭。

如果我看this然后 https://www.ag-grid.com/javascript-grid-cell-editing/#editing-api有用于编辑的可取消回调函数。但是在这个回调函数中有没有办法访问当前实例化的组件?我认为这是处理此问题的最简单方法。

我正在使用 vee-validate,所以验证函数是异步的,请记住。

最佳答案

使用整行编辑。 创建一个全局变量,如

var problemRow = -1;

然后订阅这个事件:

 onRowEditingStarted: function (event) {
    if (problemRow!=-1 && event.rowIndex!=problemRow) {
        gridOptions.api.stopEditing();
        gridOptions.api.startEditingCell({
            rowIndex: problemRow,
            colKey: 'the column you want to focus',
        });
    }
},
onRowEditingStopped: function (event) {
    if (problemRow==-1) {
        if (event.data.firstName != "your validation") {
            problemRow = event.rowIndex
            gridOptions.api.startEditingCell({
                rowIndex: problemRow,
                colKey: 'the column you want to focus',
            });
        }
    }
    if (problemRow == event.rowIndex) {
        if (event.data.firstName != "your validation") {
            problemRow = event.rowIndex
            gridOptions.api.startEditingCell({
                rowIndex: problemRow,
                colKey: 'the column you want to focus',
            });
        }
        else{
            problemRow=-1;   
        }

    }
},

关于vue.js - 如何防止在 ag-grid 中使用自定义 vue 组件验证错误时关闭单元格编辑模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56044396/

相关文章:

vue.js - 如何在vuejs中正确加载授权用户的数据

javascript - Vue $emit 不在父级内部触发

css - 垂直对齐 ag-grid 单元格内的文本

javascript - 如何将焦点设置在 onRowClicked 行中的第一个可编辑单元格上?

javascript - Vue 用 [] 括号打印我的数组,为什么?

javascript - 仅当内容与特定值匹配时才渲染 VUE 槽

angular - ag-grid csv 导出 - 使用 processCellCallback 进行格式化

filter - 如何关闭特定列的 ag-grid 快速过滤器

export - ag-grid 默认导出选择行

javascript - 在 ES6 : "Failed to resolve module specifier "vue""中导入包