Navigation Methods

Programmatically navigate through spreadsheet cells and control active cell positioning with built-in navigation methods.

What's new with Version 13

  • Excel block navigation: Ctrl + Arrow lands on the edge of the current value block, on the first value after a gap, or on the grid edge, and Ctrl + Shift + Arrow extends the selection the same way
  • Merged cells: a merge acts as one cell during the jumps, and entering a merge that starts off-screen scrolls to its start, as Google Sheets does
  • Performance: a jump across the empty tail of a million-row grid resolves in well under a millisecond, and the navigation methods work on a headless server

Documentation

Methods

Method Description
goto(y, x?) Move to specific cell coordinates.
goto(row: number, col?: number)
pageUp() Scroll up by one page.
pageUp() : void
pageDown() Scroll down by one page.
pageDown() : void
left() Move one cell left. With ctrlKey, jump to the edge of the value block.
left(shiftKey?: boolean, ctrlKey?: boolean) : void
up() Move one cell up. With ctrlKey, jump to the edge of the value block.
up(shiftKey?: boolean, ctrlKey?: boolean) : void
right() Move one cell right. With ctrlKey, jump to the edge of the value block.
right(shiftKey?: boolean, ctrlKey?: boolean) : void
down() Move one cell down. With ctrlKey, jump to the edge of the value block.
down(shiftKey?: boolean, ctrlKey?: boolean) : void
last() Move to last cell with data.
last() : void
first() Move to first cell (A1).
first() : void

Block navigation

The jumps with Ctrl + Arrow follow the Excel contract. From a value inside a block of values, the cursor lands on the last cell of the block. From a value followed by blanks, or from a blank cell, it lands on the first value after the gap. When only blanks remain, it lands on the edge of the grid. Ctrl + Shift + Arrow extends the selection to the same target.

A merged cell acts as one cell whose state is the value of its anchor: an empty merge is a blank the jumps pass through, a merge with a value stops the jump on its anchor, and a jump started inside a merge always leaves it. Entering a merge whose span starts off-screen scrolls the viewport to the start of the merge. The navigation methods work on a headless server with the same semantics; only the scroll positioning applies in the browser.

Examples

Basic Navigation

<html>
<script src="https://jspreadsheet.com/v13/jspreadsheet.js"></script>
<link rel="stylesheet" href="https://jspreadsheet.com/v13/jspreadsheet.css" type="text/css" />
<script src="https://jsuites.net/v6/jsuites.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v6/jsuites.css" type="text/css" />

<div id="spreadsheet"></div>

<p class="jss_object">
<input type="button" id="btn1" value="Left" />
<input type="button" id="btn2" value="Up" />
<input type="button" id="btn3" value="Right" />
<input type="button" id="btn4" value="Down" />
<input type="button" id="btn5" value="First" />
<input type="button" id="btn6" value="Last" />
</p>

<script>
// You can use the following license for quick testing on localhost, StackBlitz, or CodeSandbox.
// The license is valid for one day, after which the spreadsheet will become read-only.
// For a longer trial period, you can create a free account and generate a demo license with an extended expiration date.
jspreadsheet.setLicense('N2JhNDIxOTExODc4MThkZjVlNzAxY2FlN2E2ZDQzMTExMmQxZmRiMTUwODBiY2FhZDMxOTMwYjY3ZGZjODA2M2QzZDZjNGM1ZWJiNGI1ZGVjM2NmNzFlNjNkYmNiMzI3YjBkNGFhNTc0NjgxNzA5MzU2OTQ1NzMzMDg5YWRlNDAsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpnNU1qWTJOVEExTENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2liRzlqWVd4b2IzTjBJbDBzSW5Cc1lXNGlPaUl6TkNJc0luTmpiM0JsSWpwYkluWTNJaXdpZGpnaUxDSjJPU0lzSW5ZeE1DSXNJbll4TVNJc0luWXhNaUlzSW5ZeE15SXNJbU5vWVhKMGN5SXNJbVp2Y20xeklpd2labTl5YlhWc1lTSXNJbkJoY25ObGNpSXNJbkpsYm1SbGNpSXNJbU52YlcxbGJuUnpJaXdpYVcxd2IzSjBaWElpTENKaVlYSWlMQ0oyWVd4cFpHRjBhVzl1Y3lJc0luTmxZWEpqYUNJc0luQnlhVzUwSWl3aWMyaGxaWFJ6SWl3aVkyeHBaVzUwSWl3aWMyVnlkbVZ5SWl3aWMyaGhjR1Z6SWl3aVptOXliV0YwSWl3aWNHbDJiM1FpWFN3aVpHVnRieUk2ZEhKMVpYMD0=');

// Create a new spreadsheet
let spreadsheet = jspreadsheet(document.getElementById('spreadsheet'), {
    worksheets: [{
        data: [
            ['Mazda', 2001, 2000],
            ['Peugeot', 2010, 5000],
            ['Honda', 2020, 3000],
            ['Fiat', 2015, 4000],
        ],
        minDimensions: [6, 6],
    }]
});

document.getElementById("btn1").onclick = () => spreadsheet[0].left();
document.getElementById("btn2").onclick = () => spreadsheet[0].up();
document.getElementById("btn3").onclick = () => spreadsheet[0].right();
document.getElementById("btn4").onclick = () => spreadsheet[0].down();
document.getElementById("btn5").onclick = () => spreadsheet[0].first();
document.getElementById("btn6").onclick = () => spreadsheet[0].last();
</script>
</html>
import React, {useRef} from "react";
import {Spreadsheet, Worksheet, jspreadsheet} from "@jspreadsheet/react";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";

// You can use the following license for quick testing on localhost, StackBlitz, or CodeSandbox.
// The license is valid for one day, after which the spreadsheet will become read-only.
// For a longer trial period, you can create a free account and generate a demo license with an extended expiration date.
jspreadsheet.setLicense('N2JhNDIxOTExODc4MThkZjVlNzAxY2FlN2E2ZDQzMTExMmQxZmRiMTUwODBiY2FhZDMxOTMwYjY3ZGZjODA2M2QzZDZjNGM1ZWJiNGI1ZGVjM2NmNzFlNjNkYmNiMzI3YjBkNGFhNTc0NjgxNzA5MzU2OTQ1NzMzMDg5YWRlNDAsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpnNU1qWTJOVEExTENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2liRzlqWVd4b2IzTjBJbDBzSW5Cc1lXNGlPaUl6TkNJc0luTmpiM0JsSWpwYkluWTNJaXdpZGpnaUxDSjJPU0lzSW5ZeE1DSXNJbll4TVNJc0luWXhNaUlzSW5ZeE15SXNJbU5vWVhKMGN5SXNJbVp2Y20xeklpd2labTl5YlhWc1lTSXNJbkJoY25ObGNpSXNJbkpsYm1SbGNpSXNJbU52YlcxbGJuUnpJaXdpYVcxd2IzSjBaWElpTENKaVlYSWlMQ0oyWVd4cFpHRjBhVzl1Y3lJc0luTmxZWEpqYUNJc0luQnlhVzUwSWl3aWMyaGxaWFJ6SWl3aVkyeHBaVzUwSWl3aWMyVnlkbVZ5SWl3aWMyaGhjR1Z6SWl3aVptOXliV0YwSWl3aWNHbDJiM1FpWFN3aVpHVnRieUk2ZEhKMVpYMD0=');

export default function App() {
    // Spreadsheet array of worksheets
    const spreadsheet = useRef();

    // Data
    const data = [
        ['Mazda', 2001, 2000],
        ['Peugeot', 2010, 5000],
        ['Honda', 2020, 3000],
        ['Fiat', 2015, 4000],
    ];

    // Render component
    return (
        <>
            <Spreadsheet ref={spreadsheet}>
                <Worksheet data={data} minDimensions={[6, 6]} />
            </Spreadsheet>
            <input type="button" value="Left" onClick={() => spreadsheet.current[0].left()} />
            <input type="button" value="Up" onClick={() => spreadsheet.current[0].up()} />
            <input type="button" value="Right" onClick={() => spreadsheet.current[0].right()} />
            <input type="button" value="Down" onClick={() => spreadsheet.current[0].down()} />
            <input type="button" value="First" onClick={() => spreadsheet.current[0].first()} />
            <input type="button" value="Last" onClick={() => spreadsheet.current[0].last()} />
        </>
    );
}
<template>
    <Spreadsheet ref="spreadsheet">
        <Worksheet :data="data" :minDimensions="[6, 6]" />
    </Spreadsheet>
    <input type="button" value="Left" @click="$refs.spreadsheet[0].left()" />
    <input type="button" value="Up" @click="$refs.spreadsheet[0].up()" />
    <input type="button" value="Right" @click="$refs.spreadsheet[0].right()" />
    <input type="button" value="Down" @click="$refs.spreadsheet[0].down()" />
    <input type="button" value="First" @click="$refs.spreadsheet[0].first()" />
    <input type="button" value="Last" @click="$refs.spreadsheet[0].last()" />
</template>

<script>
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/vue";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";

// You can use the following license for quick testing on localhost, StackBlitz, or CodeSandbox.
// The license is valid for one day, after which the spreadsheet will become read-only.
// For a longer trial period, you can create a free account and generate a demo license with an extended expiration date.
jspreadsheet.setLicense('N2JhNDIxOTExODc4MThkZjVlNzAxY2FlN2E2ZDQzMTExMmQxZmRiMTUwODBiY2FhZDMxOTMwYjY3ZGZjODA2M2QzZDZjNGM1ZWJiNGI1ZGVjM2NmNzFlNjNkYmNiMzI3YjBkNGFhNTc0NjgxNzA5MzU2OTQ1NzMzMDg5YWRlNDAsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpnNU1qWTJOVEExTENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2liRzlqWVd4b2IzTjBJbDBzSW5Cc1lXNGlPaUl6TkNJc0luTmpiM0JsSWpwYkluWTNJaXdpZGpnaUxDSjJPU0lzSW5ZeE1DSXNJbll4TVNJc0luWXhNaUlzSW5ZeE15SXNJbU5vWVhKMGN5SXNJbVp2Y20xeklpd2labTl5YlhWc1lTSXNJbkJoY25ObGNpSXNJbkpsYm1SbGNpSXNJbU52YlcxbGJuUnpJaXdpYVcxd2IzSjBaWElpTENKaVlYSWlMQ0oyWVd4cFpHRjBhVzl1Y3lJc0luTmxZWEpqYUNJc0luQnlhVzUwSWl3aWMyaGxaWFJ6SWl3aVkyeHBaVzUwSWl3aWMyVnlkbVZ5SWl3aWMyaGhjR1Z6SWl3aVptOXliV0YwSWl3aWNHbDJiM1FpWFN3aVpHVnRieUk2ZEhKMVpYMD0=');

export default {
    components: {
        Spreadsheet,
        Worksheet,
    },
    data() {
        return {
            data: [
                ['Mazda', 2001, 2000],
                ['Peugeot', 2010, 5000],
                ['Honda', 2020, 3000],
                ['Fiat', 2015, 4000],
            ],
        };
    }
}
</script>
import { Component, ViewChild, ElementRef, AfterViewInit } from "@angular/core";
import jspreadsheet from "jspreadsheet";
import "jspreadsheet/dist/jspreadsheet.css";
import "jsuites/dist/jsuites.css";

// You can use the following license for quick testing on localhost, StackBlitz, or CodeSandbox.
// The license is valid for one day, after which the spreadsheet will become read-only.
// For a longer trial period, you can create a free account and generate a demo license with an extended expiration date.
jspreadsheet.setLicense('N2JhNDIxOTExODc4MThkZjVlNzAxY2FlN2E2ZDQzMTExMmQxZmRiMTUwODBiY2FhZDMxOTMwYjY3ZGZjODA2M2QzZDZjNGM1ZWJiNGI1ZGVjM2NmNzFlNjNkYmNiMzI3YjBkNGFhNTc0NjgxNzA5MzU2OTQ1NzMzMDg5YWRlNDAsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpnNU1qWTJOVEExTENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2liRzlqWVd4b2IzTjBJbDBzSW5Cc1lXNGlPaUl6TkNJc0luTmpiM0JsSWpwYkluWTNJaXdpZGpnaUxDSjJPU0lzSW5ZeE1DSXNJbll4TVNJc0luWXhNaUlzSW5ZeE15SXNJbU5vWVhKMGN5SXNJbVp2Y20xeklpd2labTl5YlhWc1lTSXNJbkJoY25ObGNpSXNJbkpsYm1SbGNpSXNJbU52YlcxbGJuUnpJaXdpYVcxd2IzSjBaWElpTENKaVlYSWlMQ0oyWVd4cFpHRjBhVzl1Y3lJc0luTmxZWEpqYUNJc0luQnlhVzUwSWl3aWMyaGxaWFJ6SWl3aVkyeHBaVzUwSWl3aWMyVnlkbVZ5SWl3aWMyaGhjR1Z6SWl3aVptOXliV0YwSWl3aWNHbDJiM1FpWFN3aVpHVnRieUk2ZEhKMVpYMD0=');

@Component({
    standalone: true,
    selector: "app-root",
    template: `
        <div #spreadsheet></div>
        <input type="button" value="Left" (click)="worksheets[0].left()" />
        <input type="button" value="Up" (click)="worksheets[0].up()" />
        <input type="button" value="Right" (click)="worksheets[0].right()" />
        <input type="button" value="Down" (click)="worksheets[0].down()" />
        <input type="button" value="First" (click)="worksheets[0].first()" />
        <input type="button" value="Last" (click)="worksheets[0].last()" />
    `
})
export class AppComponent implements AfterViewInit {
    @ViewChild("spreadsheet") spreadsheet: ElementRef;
    // Worksheets
    worksheets: jspreadsheet.worksheetInstance[];

    // Create a new data grid
    ngAfterViewInit() {
        // Create spreadsheet
        this.worksheets = jspreadsheet(this.spreadsheet.nativeElement, {
            worksheets: [{
                data: [
                    ['Mazda', 2001, 2000],
                    ['Peugeot', 2010, 5000],
                    ['Honda', 2020, 3000],
                    ['Fiat', 2015, 4000],
                ],
                minDimensions: [6, 6],
            }]
        });
    }
}