JQuery handsontable在渲染器后使单元格相对于其他单元格值为只读-不工作

JQuery handsontable在渲染器后使单元格相对于其他单元格值为只读-不工作,jquery,cell,readonly,handsontable,renderer,Jquery,Cell,Readonly,Handsontable,Renderer,我有一个handsontable,里面有以下数据 var data = [ ["2008", 10, 11, 12, 1], ["2009", 20, 11, 14, 0], ["2010", 30, 15, 12, 1] ]; 链接: 我需要在最后一列中假设的是,如果值为0,那么我需要包含行的第二列和第三列的对应列使其成为只读。 请注意下图以了解更多详细信息: 需要使用可切换的渲染器方法。我用的是: , 但不工作,请指导我……您不需要使用JQuery来更新只读属

我有一个
handsontable
,里面有以下数据

var data = [
    ["2008", 10, 11, 12, 1],
    ["2009", 20, 11, 14, 0],
    ["2010", 30, 15, 12, 1]
  ];
链接:

我需要在最后一列中假设的是,如果值为0,那么我需要包含行的第二列和第三列的对应列使其成为只读。

请注意下图以了解更多详细信息:

需要使用可切换的渲染器方法。我用的是:

,


但不工作,请指导我……

您不需要使用JQuery来更新只读属性

您需要创建一个单元格属性,如我的示例:


关于

您可以使用的是Handsontable中已经包含的只读属性。 请参见以下表格初始化时以及任何更改后我调用的函数:

function updateTableReadOnly() {
  var cellPropertiesID;
  for (var i = 0; i < $("#example1grid").handsontable('getData').length; i++) {
    if ($("#example1grid").handsontable('getData')[i][4] === '0') {
      updateCellReadOnly(i,2,true)
      updateCellReadOnly(i,3,true)
    } else {
      updateCellReadOnly(i,2,false)
      updateCellReadOnly(i,3,false)
    }
  }
  $("#example1grid").handsontable('render');
}

function updateCellReadOnly(i,j,value) {
  cellPropertiesID = $("#example1grid").handsontable('getCellMeta',i,j);
  cellPropertiesID.readOnly = value;
}

原因是如果您需要直接更改表中的数据,那么您将输入的新值将是一个字符串。通过这种方式,日产和丰田将根据本田的价值动态改变其性能。我想您希望在这里实现这一点。

请尝试以下片段

$(document).ready(function () {
var d = $("#example1grid").handsontable({
   colHeaders: ["", "Kia", "Nissan", "Toyota", "Honda"],
   cells: function(row, col, prop){
      const cellProperties = {};

    if (row === 1 && col === 2 || row === 1 && col === 3) {
       cellProperties.readOnly = true;  
    }

    if (row === 1 && col === 4){
       if (this.instance.getDataAtCell(row, col) === 0) {
       cellProperties.readOnly = true;  
    }
  }
    return cellProperties;
  }
});

var data = [
  ["2008", 10, 11, 12, 1],
  ["2009", 20, 11, 14, 0],
  ["2010", 30, 15, 12, 1]
];

$("#example1grid").handsontable("loadData", data);   
  //$('td').css('background-color', 'red');
});

@泽克德罗德,请帮帮我,巴迪
function updateTableReadOnly() {
  var cellPropertiesID;
  for (var i = 0; i < $("#example1grid").handsontable('getData').length; i++) {
    if ($("#example1grid").handsontable('getData')[i][4] === '0') {
      updateCellReadOnly(i,2,true)
      updateCellReadOnly(i,3,true)
    } else {
      updateCellReadOnly(i,2,false)
      updateCellReadOnly(i,3,false)
    }
  }
  $("#example1grid").handsontable('render');
}

function updateCellReadOnly(i,j,value) {
  cellPropertiesID = $("#example1grid").handsontable('getCellMeta',i,j);
  cellPropertiesID.readOnly = value;
}
var data = [
  ["2008", "10", "11", "12", "1"],
  ["2009", "20", "11", "14", "0"],
  ["2010", "30", "15", "12", "1"]
],
$(document).ready(function () {
var d = $("#example1grid").handsontable({
   colHeaders: ["", "Kia", "Nissan", "Toyota", "Honda"],
   cells: function(row, col, prop){
      const cellProperties = {};

    if (row === 1 && col === 2 || row === 1 && col === 3) {
       cellProperties.readOnly = true;  
    }

    if (row === 1 && col === 4){
       if (this.instance.getDataAtCell(row, col) === 0) {
       cellProperties.readOnly = true;  
    }
  }
    return cellProperties;
  }
});

var data = [
  ["2008", 10, 11, 12, 1],
  ["2009", 20, 11, 14, 0],
  ["2010", 30, 15, 12, 1]
];

$("#example1grid").handsontable("loadData", data);   
  //$('td').css('background-color', 'red');
});