Posted 6 May 2024, 4:27 am EST
Hi, when my
sheet.options.isProtected = true;
my context menu is disabled in all rows, how i enable for some rows only?
Forums Home / Spread / SpreadJS
Posted by: khauam.cardoso on 6 May 2024, 4:27 am EST
Posted 6 May 2024, 4:27 am EST
Hi, when my
sheet.options.isProtected = true;
my context menu is disabled in all rows, how i enable for some rows only?
Posted 6 May 2024, 11:20 pm EST
Hi,
From what I understand, when you set a sheet as protected, the context menu is disabled for all rows, meaning it doesn’t open, and you’re interested in enabling it for specific rows.
However, on my end, when I set the sheet as protected, the context menu isn’t disabled for any row. To better understand your situation, could you please share a sample document along with the steps to reproduce the behavior you’re encountering? Alternatively, you can modify the existing sample to demonstrate the issue. Providing a GIF or video showcasing the problem would also be greatly beneficial.
However, you can make the context menu open for certain rows by handling the “contextmenu” event and utilizing the hitText method to determine the cell’s location. Please refer to the attached snippet and sample for guidance on how to achieve this.
spread.getHost().addEventListener("contextmenu", (e) => {
// getting location
const offsetEle = spread.getHost();
const x = e.pageX - offsetEle.offsetLeft;
const y = e.pageY - offsetEle.offsetTop;
// finding target
const target = spread.hitTest(x, y);
if (!(target.worksheetHitInfo.hitTestType == GC.Spread.Sheets.SheetArea.viewport && target.worksheetHitInfo.row == 0)) {
e.stopPropagation();
e.preventDefault();
}
}, true)
References:
hitTest: https://developer.mescius.com/spreadjs/api/classes/GC.Spread.Sheets.Workbook#hittest
Regards,
Priyam