Posted 14 July 2021, 3:38 am EST
Hi,
Thanks for the sample. the issue is, the Click event gets fired when we release the mouse so if we release the mouse on the viewport position then hit test gives the information about the sheet not about the scrollbar.
For this, you may use the mouseDown event and perform a hit test on the workbook level so that whenever the scrollbar gets clicked you spread should provide scrollbar info. Please refer to the following code snippet and attached sample that demonstrates the same.
const clickHandler = (event) => {
event.stopPropagation();
if (spread) {
const offsetValues = document
.getElementById("spread_sheet")
?.getBoundingClientRect();
let xValue = event.clientX;
let yValue = event.clientY;
if (offsetValues) {
xValue = xValue - offsetValues?.left;
yValue = yValue - offsetValues?.top;
}
const target = spread?.hitTest(xValue, yValue);
const isColHeader = target.cellTypeHitInfo?.sheetArea === 1;
const isColHeaderDragged = target.resizeInfo?.sheetArea === 1;
if (
target.verticalScrollBarHitInfo ||
target.horizontalScrollBarHitInfo
) {
console.log("scrolBarClicked");
} else {
if (
target &&
target?.row !== undefined &&
target?.row >= 0 &&
target?.col !== undefined &&
target?.col >= 0
) {
/* here we wrapped the workbook inside a div(this is mandatory for our case)
I clicked on the scrollbar and then since the scroll is on the spreadsheet cells
we are able to get click events on cells.
How can we prevent this scroll from cell click?
*/
document.getElementById("CellClick").innerHTML =
"Cell:( " + target.row + ", " + target.col + " ) Clicked";
console.log(target.row, target.col);
}
}
}
};
sample: https://codesandbox.io/s/spread-js-starter-forked-uts8f?file=/src/index.js:1423-2840
Regards
Avinash