Getting Started with vanilla-gantt-toolbar

<vn-gantt-toolbar> is the grid toolbar for a Gantt: it links to the Gantt's task list and offers the same items and commands as <vn-grid-toolbar>, plus one of its own. Each step shows the running example and its whole source, a complete page you can copy.

What you need. Four scripts, from the build's dist/vanilla-components/latest/ folder, in this order: the grid, the grid toolbar, the Gantt, the Gantt toolbar. Start with the Gantt's getting-started guide and the grid toolbar's if they are new to you.

1. Expand all and collapse all

The gantt attribute names the Gantt by its id; the toolbar links its task list once the Gantt is initialized. The template and the items are the grid toolbar's. The standard expandAllRows and collapseAllRows commands open and close every summary at once.

Example: expand all and collapse allOpen in a new tab ↗
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>A toolbar for the Gantt</title>
  <style>
    html, body { height: 100%; margin: 0; font-family: system-ui, sans-serif; }
    body { display: flex; flex-direction: column; }
    vn-gantt { display: block; flex: 1; min-height: 0; }
  </style>
</head>
<body>
  <!-- gantt: the id of the <vn-gantt> whose task list this toolbar drives.
       The items and commands are the grid toolbar's. -->
  <vn-gantt-toolbar gantt="plan">
    <template data-vn-grid-toolbar="empty">
      <vn-grid-toolbar-status></vn-grid-toolbar-status>
      <vn-grid-toolbar-spacer grow></vn-grid-toolbar-spacer>
      <vn-grid-toolbar-command command="expandAllRows" icon="expand-all" variant="ghost"
        title-key="expandAllTitle"></vn-grid-toolbar-command>
      <vn-grid-toolbar-command command="collapseAllRows" icon="collapse-all" variant="ghost"
        title-key="collapseAllTitle"></vn-grid-toolbar-command>
    </template>
  </vn-gantt-toolbar>

  <vn-gantt id="plan"></vn-gantt>

  <!-- Load order: the grid, its toolbar, the Gantt, then the Gantt toolbar. -->
  <script src="path/to/vanilla-grid/vanilla-grid.bundle.js"></script>
  <script src="path/to/vanilla-grid-toolbar/vanilla-grid-toolbar.bundle.js"></script>
  <script src="path/to/vanilla-gantt/vanilla-gantt.bundle.js"></script>
  <script src="path/to/vanilla-gantt-toolbar/vanilla-gantt-toolbar.bundle.js"></script>
  <script type="module">
    await window.VanillaGanttReady;
    const gantt = document.getElementById('plan');
    await gantt.ready();

    const tasks = [
      { id: 'p1', parentId: null, name: 'Phase 1', start: '', end: '' },
      { id: 't1', parentId: 'p1', name: 'Design', start: '2026-11-02', end: '2026-11-05' },
      { id: 't2', parentId: 'p1', name: 'Build', start: '2026-11-05', end: '2026-11-12' },
      { id: 'p2', parentId: null, name: 'Phase 2', start: '', end: '' },
      { id: 't3', parentId: 'p2', name: 'Test', start: '2026-11-12', end: '2026-11-17' },
      { id: 'm1', parentId: 'p2', name: 'Release', start: '2026-11-17', end: '2026-11-17' },
    ];
    const dependencies = [
      { from: 't1', to: 't2' },
      { from: 't2', to: 't3' },
      { from: 't3', to: 'm1' },
    ];

    gantt.setDataManager(new VanillaGanttStaticDataManager({ tasks, dependencies }));
    // The toolbar links the task list once the Gantt is initialized.
    gantt.initializeGantt({ taskListWidth: 200 });
    await gantt.loadTasksAsync();
  </script>
</body>
</html>

2. Scroll to the selected task

Click a task's row or bar to select it. The toolbar's own command, scrollToSelectedTask, scrolls its bar into view and moves the keyboard focus to it. disabled-when="!hasSingleSelection" keeps the button off until exactly one task is selected. At the day scale most of this plan is off screen: select a late task in the list, then press the button.

Example: scroll to the selected taskOpen in a new tab ↗
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Scroll to the selected task</title>
  <style>
    html, body { height: 100%; margin: 0; font-family: system-ui, sans-serif; }
    body { display: flex; flex-direction: column; }
    vn-gantt { display: block; flex: 1; min-height: 0; }
  </style>
</head>
<body>
  <!-- scrollToSelectedTask brings the selected task's bar into view.
       disabled-when: the button is off until exactly one task is selected. -->
  <vn-gantt-toolbar gantt="plan">
    <template data-vn-grid-toolbar="empty">
      <vn-grid-toolbar-status></vn-grid-toolbar-status>
      <vn-grid-toolbar-spacer grow></vn-grid-toolbar-spacer>
      <vn-grid-toolbar-command command="scrollToSelectedTask" icon="locate" variant="ghost"
        title-key="scrollToSelectedTaskTitle" disabled-when="!hasSingleSelection"></vn-grid-toolbar-command>
    </template>
  </vn-gantt-toolbar>

  <vn-gantt id="plan" zoom="day"></vn-gantt>

  <script src="path/to/vanilla-grid/vanilla-grid.bundle.js"></script>
  <script src="path/to/vanilla-grid-toolbar/vanilla-grid-toolbar.bundle.js"></script>
  <script src="path/to/vanilla-gantt/vanilla-gantt.bundle.js"></script>
  <script src="path/to/vanilla-gantt-toolbar/vanilla-gantt-toolbar.bundle.js"></script>
  <script type="module">
    await window.VanillaGanttReady;
    const gantt = document.getElementById('plan');
    await gantt.ready();

    // Twelve one-week tasks in a row: at the day scale most bars are off screen.
    const day = 24 * 60 * 60 * 1000;
    const first = Date.UTC(2026, 10, 2);
    const tasks = Array.from({ length: 12 }, (_, i) => ({
      id: 't' + (i + 1),
      parentId: null,
      name: 'Task ' + (i + 1),
      start: first + i * 7 * day,
      end: first + (i + 1) * 7 * day,
    }));

    gantt.setDataManager(new VanillaGanttStaticDataManager({ tasks, dependencies: [] }));
    gantt.initializeGantt({ taskListWidth: 200 });
    await gantt.loadTasksAsync();
  </script>
</body>
</html>

Next steps