Navigate to Sheet Range
Programmatically navigate and scroll to specific cell ranges
The useNavigateToSheetRange hook provides a programmatic way to navigate to specific cell ranges, change sheets, and scroll to particular locations in your spreadsheet. This is useful for implementing search functionality, jumping to errors, following links, and creating guided tours.
Overview
Navigate to Sheet Range enables:
Sheet switching: Change the active sheet programmatically
Cell navigation: Jump to specific cells or ranges
Auto-scrolling: Automatically scroll cells into view
Selection updates: Update selections when navigating
Cross-sheet navigation: Navigate across different sheets
Basic Usage
import { SpreadsheetProvider } from "@rowsncolumns/spreadsheet";
import { useNavigateToSheetRange } from "@rowsncolumns/spreadsheet";
function MySpreadsheet() {
const navigateToSheetRange = useNavigateToSheetRange();
const handleNavigate = () => {
navigateToSheetRange?.({
sheetId: 2,
startRowIndex: 10,
startColumnIndex: 5,
endRowIndex: 15,
endColumnIndex: 10,
});
};
return (
<button onClick={handleNavigate}>
Go to Sheet 2, Range F11:K16
</button>
);
}Hook Usage
The hook must be used within a SpreadsheetProvider:
Function Signature
Navigation Examples
Navigate to Specific Cell
Navigate to Range
Navigate to Named Range
Complete Example
Use Cases
Search Results Navigation
Navigate to cells matching search criteria:
Error Navigation
Jump to cells with formula errors:
Table Navigation
Navigate to different sections of a table:
Hyperlink Navigation
Navigate when clicking on cell references:
Guided Tour
Create a step-by-step tour of your spreadsheet:
Advanced Features
Smooth Scrolling
Implement smooth scrolling with animation:
Navigation History
Track navigation history for back/forward buttons:
Helper Functions
Cell Address to Range
Convert cell address notation to range:
Best Practices
Validate Ranges: Ensure row and column indices are within bounds
Handle Edge Cases: Check for undefined or null navigateToSheetRange
User Feedback: Provide visual indicators during navigation
Accessibility: Support keyboard shortcuts for navigation
Performance: Avoid excessive navigation calls in loops
Troubleshooting
Navigation Not Working
Verify you're calling the hook within
SpreadsheetProviderCheck that sheet IDs and indices are valid
Ensure the component is properly mounted
Sheet Not Switching
Confirm the target sheet exists in the sheets array
Verify
onChangeActiveSheetis properly connectedCheck that sheet IDs match
Scroll Position Not Updating
Ensure row and column indices are within the sheet bounds
Verify the grid is properly rendered
Check for conflicting scroll handlers
Last updated
Was this helpful?