Posted 16 May 2023, 9:29 pm EST
Is there an event in GrapeCity SpreadJS that is triggered when using the “Find & Goto” feature, or is there a workaround to detect when a cell is highlighted?
Many thanks
Forums Home / Spread / SpreadJS
Posted by: datnguyen4326 on 16 May 2023, 9:29 pm EST
Posted 16 May 2023, 9:29 pm EST
Is there an event in GrapeCity SpreadJS that is triggered when using the “Find & Goto” feature, or is there a workaround to detect when a cell is highlighted?
Many thanks
Posted 17 May 2023, 8:24 pm EST - Updated 17 May 2023, 8:29 pm EST
Hi,
Currently, there is no direct Event that is triggered when using the “Find & GoTo” feature.
However, you could override the “goto” command, get the SpreadJS Designer’s Dialog and add the click handler to the “OK” button. You can get the getSelections() method to get the selections.
Kindly refer to the following code snippet and the sample:
let config = GC.Spread.Sheets.Designer.DefaultConfig;
var oldGoToCommand = GC.Spread.Sheets.Designer.getCommand(GC.Spread.Sheets.Designer.CommandNames.FindDialogGoto).execute;
config.commandMap = {
"goto": {
execute: function () {
let result = oldGoToCommand.apply(this, arguments);
let gotoDialogEl = document.querySelector("div.gc-sjs-designer-dialog");
if (gotoDialogEl) {
let okButtonEl = gotoDialogEl.querySelectorAll("button.gc-ui-button")[1];
if (okButtonEl) {
okButtonEl.addEventListener("click", function () {
setTimeout(() => {
if (!document.querySelector("div.gc-sjs-designer-dialog")) {
console.log("Go to Event");
let selections = spread.getActiveSheet().getSelections()[0];
console.log("Sheet Name: " + spread.getActiveSheet().name());
console.log("Range: " + GC.Spread.Sheets.CalcEngine.rangeToFormula(
new GC.Spread.Sheets.Range(selections.row, selections.col, selections.rowCount, selections.colCount))
);
console.log("Selections: ");
console.log(selections);
}
}, 100)
}, true);
}
}
return result;
}
}
}
designer.setConfig(config);
References:
FindDialogGoTo Command: https://www.grapecity.com/spreadjs/api/v15/designer/classes/GC.Spread.Sheets.Designer.CommandNames#finddialoggoto
getSelections method: https://www.grapecity.com/spreadjs/api/v15/classes/GC.Spread.Sheets.Worksheet#getselections
rangeToFormula method: https://www.grapecity.com/spreadjs/api/modules/GC.Spread.Sheets.CalcEngine#rangetoformula
Regards,
Ankit