如何触发 handsontable row/cell 上的点击?

How to trigger a click on a handsontable row/cell?

我设置了一个 afterOnCellMouseDown 事件,单击单元格后我需要做很多事情。

我想知道是否有办法在 handsontable 的单元格上触发点击事件?

我知道有一种方法可以 select 一行或一列,但我特别需要触发一个点击事件,以便触发我的 afterOnCellMouseDown。

有什么想法吗?

谢谢!

Handsontable 团队的 Piotr 帮助我解决了这个问题。 他准备了演示 这是一个 link - https://jsfiddle.net/mfhqz69L/

你需要知道 handsontable 不能监听点击,因为点击是在一个完整的点击动作发生后触发的;也就是说,按下并释放鼠标按钮,同时指针保留在同一元素内。最初按下按钮时会触发 mousedown。 这是一份 link 到完整的文档 - https://developer.mozilla.org/en-US/docs/Web/API/Element/mousedown_event

var hot = new Handsontable(hotElement, hotSettings);

function triggerMouseEvent(type, target) {
  const event = document.createEvent('MouseEvent');

  event.initMouseEvent('mousedown', true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
  target.dispatchEvent(event);
}

var hotCell = hot.getCell(0, 0);

triggerMouseEvent('mousedown', hotCell);

我不确定这是否是您要找的东西,但这是我正在做的事情。它非常适合我的需要。

afterOnCellMouseDown: function(event, coords) {
    if(coords.col == 18) // Column 18 of my table
    {
        let $id = hot.getDataAtCell(coords.row, 0); // row number and column number
        //console.log($id); // testing the results
        let $details = getOrderDetails($id); // function to pull in data to another section of the DOM
    } else {
       clearDetailInformation(); // functions to clear a few sections of the DOM
    } // end if
    hot.selectRows(coords.row); // puts a border around the clicked ROW
    } // end afterOnCellMouseDown