禁用 handsontable 中的前两列移动

Disable first two column move in handsontable

我使用 handsontable table 并且其中有 5 列,其中 manualColumnMovetrue,这样用户就可以移动列了。

但是我想为前两列禁用此功能,我该怎么做??

一种方法是防止在 beforeColumnMove 中移动列,示例:

function setBeforeColumnMove() {
    return function(startColumn, endColumn) {
        var manualColumnMove = this.getPlugin("ManualColumnMove");

        if(startColumn < 2 || endColumn < 2) {
            manualColumnMove.changeColumnPositions(endColumn, startColumn);
        }
    }
};

看这个例子:JSFiddle

祝你好运;)

在 handsontable 0.34.0 中,可以通过从 beforeColumnMove hook/callback.

返回 false 来防止行或列移动

我已经相应地调整了Joakim Si Ali的fiddle:

document.addEventListener("DOMContentLoaded", function() {

  var
    data1 = [
      ['', 'Kia', 'Nissan', 'Toyota', 'Honda', 'Mazda', 'Ford'],
      ['2012', 10, 11, 12, 13, 15, 16],
      ['2013', 10, 11, 12, 13, 15, 16],
      ['2014', 10, 11, 12, 13, 15, 16],
      ['2015', 10, 11, 12, 13, 15, 16],
      ['2016', 10, 11, 12, 13, 15, 16]
    ],
    container1 = document.getElementById('example1'),
    settings1 = {
      data: data1,
      manualColumnMove: true,
      beforeColumnMove: beforeColumnMove(),
      colHeaders: true,
    },
    hot1;

  hot1 = new Handsontable(container1, settings1);

  function beforeColumnMove() {
    return function(columnsMoving, target) {
      if (columnsMoving[0] < 2 || target < 2) {
        return false;
      }
      return true;
    }
  };
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/handsontable/0.34.0/handsontable.full.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/handsontable/0.34.0/handsontable.full.min.js"></script>
<div id="example1" class="hot handsontable"></div>