Vanilla Gantt Toolbar

<vn-gantt-toolbar gantt="<id>">: a <vn-grid-toolbar> linked to the task grid of a <vn-gantt>, named by the Gantt's own id. It cannot work standalone: it extends the grid toolbar and links a Gantt's grid.

Features

Installation

Direct File Include

<script src="path/to/vanilla-grid/vanilla-grid.js"></script>
<script src="path/to/vanilla-grid-toolbar/vanilla-grid-toolbar.js"></script>
<script src="path/to/vanilla-gantt/vanilla-gantt.js"></script>
<script src="path/to/vanilla-gantt-toolbar/vanilla-gantt-toolbar.js"></script>

vanilla-grid-toolbar.js (or its bundle) must load first: this script extends its class and logs an error, defining nothing, when it is missing. The Gantt's script may load before or after this one: the toolbar only needs the Gantt when it links. The element has no stylesheet of its own; the grid toolbar's base and theme sheets apply to its tag.

In dist/ the file ships as vanilla-gantt-toolbar.bundle.js, with vanilla-gantt-toolbar.d.ts beside it.

Usage

New to the toolbar? Getting started builds one step by step, with a live example at each step.

<vn-gantt-toolbar gantt="projectGantt">
  <template data-vn-grid-toolbar="empty">
    <vn-grid-toolbar-group align="start">
      <vn-grid-toolbar-status></vn-grid-toolbar-status>
    </vn-grid-toolbar-group>
    <vn-grid-toolbar-group align="end">
      <vn-grid-toolbar-search delay="400"></vn-grid-toolbar-search>
      <vn-grid-toolbar-command command="expandAllRows" icon="expand-all" variant="ghost"
        title-key="expandAllTitle" show-when="isTreeMode"></vn-grid-toolbar-command>
      <vn-grid-toolbar-command command="collapseAllRows" icon="collapse-all" variant="ghost"
        title-key="collapseAllTitle" show-when="isTreeMode"></vn-grid-toolbar-command>
      <vn-grid-toolbar-command command="scrollToSelectedTask" icon="locate" variant="ghost"
        title-key="scrollToSelectedTaskTitle" disabled-when="!hasSingleSelection"></vn-grid-toolbar-command>
      <vn-grid-toolbar-command command="autoFitTaskList" icon="auto-fit" variant="ghost"
        title-key="autoFitTaskListTitle"></vn-grid-toolbar-command>
    </vn-grid-toolbar-group>
  </template>
</vn-gantt-toolbar>

<vn-gantt id="projectGantt"></vn-gantt>
const gantt = document.getElementById('projectGantt');
await gantt.ready();
gantt.setDataManager(manager);
gantt.initializeGantt();   // the toolbar links the task grid now

The templates, items and commands are the grid toolbar's: see vanilla-grid-toolbar/README.md.

scrollToSelectedTask and autoFitTaskList are the commands of its own. scrollToSelectedTask ignores arg and returns the Gantt's scrollToTask(key, { focus: true }) for the one selected task, or false when unlinked or without exactly one selected task. It runs through dispatchCommand(), so a vn-grid-toolbar-command listener can veto it with preventDefault(), and registerCommand('scrollToSelectedTask', fn) replaces it. setMessages({ scrollToSelectedTaskTitle }) localizes its title.

autoFitTaskList passes arg to the task grid's autoFitAllColumns(), then calls the Gantt's fitTaskListWidth(), and returns the auto-fit's boolean, or false when unlinked. The task list is fitted even when no column was (every column non-resizable). It is vetoed, replaced and localized the same way (autoFitTaskListTitle, 'Auto-fit columns and task list'), and the export gate disables it during an export. The inherited autoFitAllColumns is unchanged: it fits the columns and leaves the task list's width alone.

Attributes

Attribute Description
gantt The id of a <vn-gantt>. Resolved on every link, so the Gantt may not exist yet. The toolbar links its task grid once the Gantt is initialized. An id naming another element warns once, then waits for a <vn-gantt> to take it.
grid Ignored, with a warning that names gantt.
theme, theme-css-path, locale As on <vn-grid-toolbar>.

Properties

Property Type Description
gantt VanillaGanttElement | null (get), VanillaGanttElement | string | null (set) Get: the linked <vn-gantt>, or null. Set an id and it is stored as the gantt attribute; set an element and it is stored, with the attribute synced to its id (removed when it has none).
grid HTMLElement | null Get: the linked task grid, which the items and commands read. Set: ignored, with a warning.

Every other property, method and event is <vn-grid-toolbar>'s. setGrid() is ignored, with a warning.

Architecture

The element is a subclass, class VanillaGanttToolbarElement extends VanillaGridToolbarElement, exported as window.VanillaGanttToolbarElement. It overrides the grid toolbar's link steps (resolve the named target, then a fallback) to resolve its gantt attribute and link no fallback; the grid toolbar's wait does the rest. See docs/vanilla-gantt-toolbar/00-index.md.

File Structure

vanilla-gantt-toolbar/
├── vanilla-gantt-toolbar.js     # the <vn-gantt-toolbar> element
├── vanilla-gantt-toolbar.d.ts   # hand-authored TypeScript declarations
└── README.md

Changelog

Version 1.1.0

Version 1.0.1

Version 1.0.0

License

MIT