如何触发可操作的行/单元格的点击?

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

我想找出是否有一种方法可以在可手动操作的单元格上触发点击事件?

我知道有一种选择行或列的方法,但是我特别需要触发click事件,以便触发我的afterOnCellMouseDown。

有什么想法吗?

谢谢!

zqx9665 回答:如何触发可操作的行/单元格的点击?

Handsontable团队的负责人在这个问题上帮助了我。 他准备了演示 这是链接-https://jsfiddle.net/mfhqz69L/

您需要知道handontable无法监听点击,因为在执行完全点击操作后会触发点击;也就是说,当指针停留在同一元素内时,按下并释放鼠标按钮。最初按下按钮后即触发mousedown。 这是完整文档的链接-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,window,80,20,false,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
本文链接:https://www.f2er.com/2399831.html

大家都在问