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
- Linked in markup:
gantt="<id>"names the<vn-gantt>; no link code afterinitializeGantt() - Waits for its Gantt: the Gantt may be added, upgraded and initialized after the toolbar; the toolbar links the task grid as soon as
getTaskGrid()returns it, and stays unlinked (silently) until then - Scroll to task: a built-in
scrollToSelectedTaskcommand (message keyscrollToSelectedTaskTitle, iconlocate) expands the selected task's ancestors, centres its row, scrolls its bar into view and focuses the timeline: the way back to the selection after scrolling away (a selection change already scrolls the timeline to the selected bar); gate it withdisabled-when="!hasSingleSelection" - Auto-fit columns and task list: a built-in
autoFitTaskListcommand (message keyautoFitTaskListTitle, iconauto-fit) fits the task grid's columns, as the inheritedautoFitAllColumnsdoes, then moves the splitter to the last column's right edge (the Gantt'sfitTaskListWidth()), as far as the timeline's minimum width allows - Everything
<vn-grid-toolbar>has: templates and their states, items, standard commands and predicates,state,ready(), events, messages, locale and themes are inherited, unchanged - One link only: no fallback to another Gantt or grid, and the inherited
gridattribute andsetGrid()are ignored with a warning - Follows the Gantt's theme: the Gantt gives its task grid its own theme, and the toolbar mirrors the linked grid's
- Zero dependencies beyond the grid toolbar and the Gantt
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
- Added (
vanilla-gantt-toolbar) - built-inautoFitTaskListcommand (message keyautoFitTaskListTitle, iconauto-fit): auto-fits the task grid's columns, then calls the Gantt'sfitTaskListWidth()so the splitter moves to the last column's right edge. The inheritedautoFitAllColumnsis unchanged. - Maintenance -
docs/vanilla-gantt-toolbar/updated.
Version 1.0.1
- Maintenance -
docs/vanilla-gantt-toolbar/gained a getting-started guide, linked from the README; no behavior change.
Version 1.0.0
- Added (
vanilla-gantt-toolbar) - first release: the<vn-gantt-toolbar>custom element, a<vn-grid-toolbar>linked by agantt="<id>"attribute to the task grid of a<vn-gantt>, which it waits for until the Gantt is initialized. Shipped asvanilla-gantt-toolbar.bundle.jswith hand-authoredvanilla-gantt-toolbar.d.ts. - Maintenance -
docs/vanilla-gantt-toolbar/added.
License
MIT