Posted 6 July 2023, 12:16 pm EST
- Updated 6 July 2023, 12:21 pm EST
Hi,
The SelectionChanging/SelectionChanged Event doesn’t trigger when the Selection is made in the Find Dialog. This behavior is by design and is expected.
For your use case, you could add a click listener to detect if the “Find All” button is clicked, and then get the inner workbook of the “Find Dialog”. After getting the inner workbook of the “Find Dialog” , you could attached a “Selection Changed” event which gets triggered when the Selection is changed.
Kindly refer to the following code snippet and the attached sample:
// Add Click Event to the window
window.addEventListener("click", function (e) {
// Check if the "Find All" button is clicked and it is present inside the SpreadJS Designer's dialog
if (e.target && (e.target.innerText === "Find All" || (e.target.childNodes && e.target.childNodes[0] && e.target.childNodes[0].innerText === "Find All"))
&& e.target.closest(".gc-sjs-designer-dialog")) {
setTimeout(() => {
let editorSpread = GC.Spread.Sheets.findControl(document.querySelector(".gc-sjs-designer-dialog").querySelector('div[gcuielement="gcSpread"]'));
if (editorSpread) {
let activeSelection = spread.getActiveSheet().getSelections()[0];
let firstSelection = true;
// Log the first searched Cell's Index
console.log("Searched Cell Row Index: " + activeSelection.row + " ,Searched Cell Column Index: " + activeSelection.col);
// Bind the Selection Changed Event
editorSpread.bind(GC.Spread.Sheets.Events.SelectionChanged, function (sender, args) {
// Check if the selected row is not the first row which is already selected
if (!(firstSelection && (args.newSelections[0].row === 0))) {
console.log('selection changed');
activeSelection = spread.getActiveSheet().getSelections()[0];
console.log("Searched Cell Row Index: " + activeSelection.row + " ,Searched Cell Column Index: " + activeSelection.col);
// Execute your custom command here
}
firstSelection = false;
})
}
});
}
}, true);
Sample: https://jscodemine.grapecity.com/share/POTTmIWVoU_aYFx6MWn9AQ/?IsEmbed=false&Theme=Unset&PreviewDirection=0&IsEditorShow=true&IsExplorerShow=true&IsPreviewShow=true&IsConsoleShow=true&IsRunBTNShow=false&IsResetBTNShow=false&IsOpenInCodemineBTNShow=false&PanelWidth=20&PanelWidth=50&PanelWidth=30&defaultOpen={"OpenedFileName"%3A["%2Findex.html"%2C"%2Fpackage.json"%2C"%2Fsrc%2Fapp.js"]%2C"ActiveFile"%3A"%2Fsrc%2Fapp.js"}
References:
getSelections method: https://www.grapecity.com/spreadjs/api/v15/classes/GC.Spread.Sheets.Worksheet#getselections
SelectionChanged Event: https://www.grapecity.com/spreadjs/api/classes/GC.Spread.Sheets.Events#selectionchanged
Please let us know if you face any issues.
Regards,
Ankit
