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

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:

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:

Track navigation history for back/forward buttons:

Helper Functions

Cell Address to Range

Convert cell address notation to range:

Best Practices

  1. Validate Ranges: Ensure row and column indices are within bounds

  2. Handle Edge Cases: Check for undefined or null navigateToSheetRange

  3. User Feedback: Provide visual indicators during navigation

  4. Accessibility: Support keyboard shortcuts for navigation

  5. Performance: Avoid excessive navigation calls in loops

Troubleshooting

  • Verify you're calling the hook within SpreadsheetProvider

  • Check 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 onChangeActiveSheet is properly connected

  • Check 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?