Inline Editing

ApexGantt provides several layers of interactive editing. Each layer is opt-in and can be combined independently.

Editing modes

OptionWhat it enables
enableTaskDragDrag task bars horizontally to reschedule (it does not reorder rows)
enableTaskResizeDrag the left or right handle of a bar to change start or end date
enableProgressDragDrag the small handle at the bar's bottom edge to set completion percent
enableTaskEditDouble-click a task bar, or press Enter on a focused bar, to open a dialog form (name, dates, progress)
enableInlineEditDouble-click a cell in the task list to edit it in place
enableTaskCRUDToolbarShow Add and Delete buttons in the toolbar
enableContextMenuRight-click a bar or row for a contextual action menu
enableAddTaskRowShow a "+ Add task" row at the bottom of the task list
enableTaskEditingShortcutsDelete/Backspace to delete focused row; Tab/Shift+Tab to indent/outdent

All edits pass through the same command path, so they are all undoable via undo().

Since 3.20.0 every committed edit fires taskUpdate and then taskUpdateSuccess once, whichever path it came from, with a source field on both details: 'drag', 'resize', 'progress', 'dialog', 'inline', 'keyboard' or 'api' (for updateTask()). They do not fire for undo/redo or for updateTask(id, changes, { silent: true }). taskDragged, taskResized and taskProgressChanged still fire too, after the commit is accepted, so an app that saves on both taskDragged and taskUpdateSuccess now saves twice: pick one. Before 3.20.0, taskUpdate and taskUpdateSuccess fired only for the dialog and inline edits.

taskUpdateError fires when a commit throws, on every path since 3.20.0: updateTask() still throws afterwards, while the interactive paths log the error, repaint the bar and carry on. taskValidationError fires when the dialog form fails its own field validation.

When a parent bar is dragged or moved with the keyboard, its descendants move with it and the gesture is committed as one batch. Each task still gets beforeTaskUpdate, taskUpdate and taskUpdateSuccess, but since 3.20.0 all of the gesture's taskUpdate events fire first and its taskUpdateSuccess events follow, after the data is rebuilt. Since 3.20.0 descendants with no startTime (undated summary rows) are not edited by a parent drag, so they no longer get update events reporting Invalid Date.

A drag or resize that ends on the task's original dates commits nothing: beforeTaskUpdate, taskUpdate, taskUpdateSuccess, taskDragged and taskResized do not fire, no undo step is recorded, and the bar (with any children it carried) goes back where it started. That holds for a bar released inside the snap unit it started in and, since 3.20.0, for one that calendar snapping puts back on its own dates, such as a Monday task dragged back onto Sunday, which calendar.dragSnapMode: 'next' returns to that Monday. Dates are compared by value, so a different spelling of the same date counts as unchanged. Before 3.20.0 the snapped-back case committed the unchanged dates, fired the events and recorded an undo step.

Since 3.20.0 the bar's aria-label, aria-valuenow and aria-valuetext are refreshed after every accepted edit (drag, resize, progress drag, dialog, inline, updateTask()); before, only keyboard edits refreshed them.

Minimal interactive setup

const gantt = new ApexGantt(document.getElementById('chart'), {
  series: tasks,
  enableTaskDrag: true,
  enableTaskResize: true,
  enableProgressDrag: true,
})

Dialog edit

Setting enableTaskEdit: true opens an edit form when a task bar is double-clicked, or when Enter or Space is pressed on a focused bar. The form exposes name, start date, end date, and progress. Summary bars do not open it: clicking a summary bar expands or collapses its children.

Since 3.20.0 the dialog reads dates in ISO and in other formats as well as inputDateFormat, uses a date-and-time input when the format carries time, and shows an empty field for a date it cannot read instead of writing Invalid Date. A save that beforeTaskUpdate vetoes keeps the dialog open, and a save with no changes commits nothing and fires no events. Before 3.20.0 ISO dates under the default format showed as empty fields, an untouched save could store Invalid Date, and formats with time lost the time.

enableInlineEdit is auto-enabled when enableTaskEdit is true. To keep only the dialog without cell-level editing, opt out explicitly:

const gantt = new ApexGantt(el, {
  series: tasks,
  enableTaskEdit: true,
  enableInlineEdit: false,   // keep dialog, disable double-click cell edit
})

Inline cell editing

With enableInlineEdit: true, double-clicking a name, startTime, endTime, duration, or progress cell turns it into an input:

  • Enter or blur commits the value
  • Escape cancels and restores the original value

Summary rows, milestones (date/duration/progress cells), and empty rows are not editable inline.

Fixed in 3.20.0:

  • Typed spaces and the Home and End keys stay in the editor; before, the chart's row navigation took them.
  • Cancelling, a beforeTaskUpdate veto, or leaving the editor unchanged restores the cell with its expand arrow still working.
  • An editor (Start, End, Duration) left without a change commits nothing: no taskUpdate / taskUpdateSuccess and no undo step. Dates are compared by value, so an ISO date in a MM-DD-YYYY chart is not rewritten by an untouched editor, and in working-day mode a task ending on a weekend, or one that runs only on weekend days, keeps its stored end.

The Duration editor

The Duration editor uses the same rule and units as the Duration column (one shared helper), so the number you type matches the number the cell shows:

  • It counts base units of snapUnit (45 m, 6 h, 14 d) and steps by snapValue. Typing 2 with snapUnit: 'day' and snapValue: 7 gives 2 days, not 8.
  • With a calendar and day snapping it counts working days (the wd the column shows), for any date format, including formats with time.
  • Without a calendar, day snapping with a time format counts day boundaries.
  • The new end keeps the current end's time of day.

Before 3.20.0 the number was not in the column's units: with snapValue: 7, typing 2 gave 8 days.

const gantt = new ApexGantt(el, {
  series: tasks,
  enableInlineEdit: true,
})

CRUD toolbar

enableTaskCRUDToolbar: true adds + Add Task and a trash-icon Delete button to the toolbar. The delete button operates on the current selection (requires enableSelection: true). Undo/Redo buttons also appear automatically.

const gantt = new ApexGantt(el, {
  series: tasks,
  enableTaskCRUDToolbar: true,
  enableSelection: true,
  enableTaskEdit: true,
})

Context menu

enableContextMenu: true shows a right-click menu on task bars and task-list rows. Available entries depend on the task type and enabled options:

  • Edit: requires enableTaskEdit: true
  • Add child / Add sibling: inserts a new task in the hierarchy
  • Indent / Outdent: available only when a valid sibling or parent exists
  • Delete: deletes the task with cascade: 'children'
const gantt = new ApexGantt(el, {
  series: tasks,
  enableContextMenu: true,
  enableTaskEdit: true,
})

Add task row

enableAddTaskRow: true renders a + Add task button row below the last task. Clicking it inserts a new root-level placeholder and emits taskAdded. The row hides while more than 50 rows are visible, because row virtualization is active then. Use the toolbar or context menu in that case.

const gantt = new ApexGantt(el, {
  series: tasks,
  enableAddTaskRow: true,
})

Keyboard shortcuts

enableTaskEditingShortcuts: true adds:

  • Delete or Backspace: deletes the focused row (cascade: 'children')
  • Tab: indent (make the row a child of the row above it)
  • Shift+Tab: outdent (promote the row to the parent's sibling)

The task list panel must have keyboard focus. Standard roving-tabindex navigation (ArrowUp, ArrowDown, Home, End) is always available regardless of this option.

Moving and resizing a bar from the keyboard

Since 3.20.0, a focused task bar responds to the arrow keys:

  • ArrowLeft / ArrowRight move the bar by one snap unit (requires enableTaskDrag).
  • Shift+ArrowLeft / Shift+ArrowRight move its end by one snap unit (requires enableTaskResize; not on milestones).

The keys are mirrored in right-to-left charts. A keyboard edit takes the same commit path as a drag: it runs beforeTaskUpdate, is undoable, and fires taskUpdate / taskUpdateSuccess with source: 'keyboard' (not taskDragged or taskResized, which belong to the pointer gestures). Focus stays on the bar. Before 3.20.0 a focused bar handled only Enter and Space.

With a calendar and day snapping, a keyboard step skips non-working days in the direction of travel (unless calendar.dragSnapMode is 'allow'). Moving a parent bar moves its children too. Each bar lists the keys that work for it in aria-keyshortcuts.

const gantt = new ApexGantt(el, {
  series: tasks,
  enableTaskEditingShortcuts: true,
  enableSelection: true,
})

Snapping drag and resize

By default, bars snap to whole-day boundaries. Use snapUnit and snapValue to snap to finer increments:

const gantt = new ApexGantt(el, {
  series: tasks,
  enableTaskDrag: true,
  enableTaskResize: true,
  snapUnit: 'hour',    // 'day' | 'hour' | 'minute'
  snapValue: 4,        // snap to every 4 hours
})
ExamplesnapUnitsnapValue
Whole day (default)'day'1
Half day'hour'12
4-hour blocks'hour'4
15-minute slots'minute'15
30-minute slots'minute'30

Since 3.20.0, with snapUnit: 'day' a mouse drag or resize and a keyboard move or resize step by calendar days. In time zones with daylight saving, a one-day step across the clock change no longer leaves the date unchanged (stretching the task instead of moving it) or jumps two days. Hour and minute snaps still step by elapsed time.

Validating edits with beforeTaskUpdate

Use the beforeTaskUpdate hook to intercept and veto an edit before it commits. The hook receives one object, { task, updates }: the task as it is now and the partial update about to be applied.

Since 3.20.0 it runs for every edit path: drag, resize, progress drag, dialog save, inline edit, keyboard move or resize, and updateTask(). Before 3.20.0 it ran only for inline edits and updateTask().

Return false to reject; any other return value allows the edit. Dates in updates are strings in inputDateFormat:

const gantt = new ApexGantt(el, {
  series: tasks,
  enableTaskDrag: true,
  enableTaskResize: true,
  inputDateFormat: 'YYYY-MM-DD',
  beforeTaskUpdate: ({ task, updates }) => {
    // prevent moving tasks into the past (ISO strings compare in date order)
    const today = new Date().toISOString().slice(0, 10)
    if (updates.startTime && updates.startTime < today) {
      return false
    }
    // prevent progress going backwards
    if (updates.progress !== undefined && updates.progress < task.progress) {
      return false
    }
    return true
  },
})

When the hook returns false, nothing is stored, no update event fires, nothing is recorded in undo history (so no historyChange either), and the bar is repainted from the data. The hook is synchronous: returning a Promise does not veto the edit.

During a parent drag or keyboard move the hook is asked about the parent and then each child that moves with it. Since 3.20.0, returning false for one child keeps only that child in place: the hook is still asked about the later siblings and they move. Returning false for the parent skips all its children. Before 3.20.0 a child veto skipped every later sibling without asking the hook, and taskDragged.affectedChildTasks left them out.

Full interactive configuration example

const gantt = new ApexGantt(document.getElementById('chart'), {
  series: tasks,

  // drag and resize
  enableTaskDrag: true,
  enableTaskResize: true,
  enableProgressDrag: true,
  snapUnit: 'hour',
  snapValue: 4,

  // forms and cell editing
  enableTaskEdit: true,
  enableInlineEdit: true,

  // affordances
  enableTaskCRUDToolbar: true,
  enableContextMenu: true,
  enableSelection: true,
  enableTaskEditingShortcuts: true,

  // undo/redo
  history: { enabled: true, maxSize: 50 },

  // validation
  beforeTaskUpdate: ({ task, updates }) => {
    // add your validation logic here
    return true
  },
})

gantt.render()

// events are dispatched on the container element you passed to the constructor
const container = document.getElementById('chart')

container.addEventListener('taskUpdateSuccess', (e) => {
  // since 3.20.0 e.detail.source says which path made the edit
  console.log('Saved:', e.detail.taskId, e.detail.source)
  // persist to your backend
})

container.addEventListener('taskValidationError', (e) => {
  console.warn('Dialog validation failed:', e.detail.errors)
})

React example

import { ApexGanttChart } from 'react-apexgantt'
import type { GanttUserOptions } from 'react-apexgantt'

const options: Omit<GanttUserOptions, 'series'> = {
  enableTaskDrag: true,
  enableTaskResize: true,
  enableProgressDrag: true,
  enableTaskEdit: true,
  enableInlineEdit: true,
  enableContextMenu: true,
  enableTaskCRUDToolbar: true,
  enableSelection: true,
  snapUnit: 'hour',
  snapValue: 4,
  inputDateFormat: 'YYYY-MM-DD',
  beforeTaskUpdate: ({ updates }) => {
    const today = new Date().toISOString().slice(0, 10)
    if (updates.startTime && updates.startTime < today) {
      return false
    }
    return true
  },
}

export default function EditableGantt() {
  return (
    <ApexGanttChart
      tasks={tasks}
      options={options}
      height="600px"
      onTaskUpdateSuccess={(detail) => {
        // persist to backend
        console.log('Updated:', detail)
      }}
      onTaskValidationError={(detail) => {
        console.warn('Validation failed:', detail)
      }}
    />
  )
}