Posted 1 September 2021, 12:32 am EST
Hi Davide,
For this whenever you get the result from searching, before changing the selection you just need to check the cell is visible or not. Please refer to the following code snippet and attached sample that demonstrates the same.
if (searchResult != null && searchResult.searchFoundFlag != spreadNS.Search.SearchFoundFlags.none) {
spread.setActiveSheetIndex(searchResult.foundSheetIndex);
var sheet = spread.getActiveSheet();
if (isVisibleCell(sheet, searchResult.foundRowIndex, searchResult.foundColumnIndex)) {
sheet.setActiveCell(searchResult.foundRowIndex, searchResult.foundColumnIndex);
if ((searchCondition.searchFlags & spreadNS.Search.SearchFlags.blockRange) == 0) {
sheet.setActiveCell(searchResult.foundRowIndex, searchResult.foundColumnIndex, 1, 1);
}
/*scrolling*/
if (searchResult.foundRowIndex < sheet.getViewportTopRow(1) ||
searchResult.foundRowIndex > sheet.getViewportBottomRow(1) ||
searchResult.foundColumnIndex < sheet.getViewportLeftColumn(1) ||
searchResult.foundColumnIndex > sheet.getViewportRightColumn(1)
) {
if (isVisibleCell(sheet, searchResult.foundRowIndex, searchResult.foundColumnIndex)) {
sheet.showCell(searchResult.foundRowIndex,
searchResult.foundColumnIndex,
spreadNS.VerticalPosition.center,
spreadNS.HorizontalPosition.center);
}
} else {
sheet.repaint();
}
}else{
/*hidden cell*/
alert('Not Found or may be hidden');
}
} else {
/*Not Found */
alert('Not Found');
}
function isVisibleCell(sheet, row, col) {
return sheet.getRowVisible(row) && sheet.getColumnVisible(col)
}
Regards,
Avinash
basicSearch.zip