javascript 在 Slick 网格中禁用特定单元格编辑

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

Disabling specific cell edit in Slick grid

javascriptslickgrid

提问by emphaticsunshine

Is there a way to disable a cell for editing? We can define editor at column level but can we disable that editor for specific rows?

有没有办法禁用单元格进行编辑?我们可以在列级别定义编辑器,但我们可以为特定行禁用该编辑器吗?

回答by Tin

grid.onBeforeEditCell.subscribe(function(e,args) {
  if (!isCellEditable(args.row, args.cell, args.item)) {
    return false;
  }
});

回答by icl7126

You can disable or even change editor/formatter/validator... or other cell properties using getItemMetadatamethod. There is very nice documentation for this here.
Example:

您可以使用getItemMetadata方法禁用甚至更改编辑器/格式化程序/验证程序...或其他单元格属性。有非常好的文档,这在这里
例子:

$scope.data.data.getItemMetadata = function (row) {
  var item = $scope.data.data.getItem(row);
  if (item.some_condition) {
    return {
      columns : {
        yourColumnId : {
          editor : null,
          formatter : function () { return 'custom formater if some_condition'; }
        }
      }
    };
  }
};