Split Tasks
A task can be split into several worked segments separated by gaps on a single row: work Monday to Wednesday, pause, resume Friday. The segments render as separate bar pieces joined by a thin connector, while the task keeps one row and one identity.
Defining segments in data
Add a segments array to a task. Each TaskSegment has a start and an end (not startTime / endTime), parsed with inputDateFormat:
const gantt = new ApexGantt(el, {
inputDateFormat: 'YYYY-MM-DD',
series: [
{
id: 't1',
name: 'Build',
segments: [
{ start: '2026-06-01', end: '2026-06-04' },
{ start: '2026-06-08', end: '2026-06-12' },
],
},
],
})
The task's own startTime / endTime are the envelope (first segment start to last segment end) and are derived automatically, so a split task can omit them. Summary rollups, dependencies, the timeline header, and the Duration column all keep working against that envelope. (In TypeScript, leaving out startTime compiles from 3.20.0, where it became optional.)
How split bars behave
- The bar draws one filled piece per segment, joined by a thin connector.
- Progress fills the worked spans left to right.
- Dragging the bar moves all segments together.
- Resizing a handle adjusts the outer segment.
Splitting at runtime
splitTask(id, at, options?) cuts the segment containing at so its first piece ends at at and the rest resumes at options.resumeAt. The default resumeAt is the day after at, which leaves no visible gap when dates are whole days, so pass a later date to open one. A task with no segments yet is treated as a single span.
// the second segment runs 06-08 to 06-12: work it on the 8th and 9th,
// pause on the 10th, and resume on the 11th
gantt.splitTask('t1', '2026-06-09', { resumeAt: '2026-06-11' })
at must fall strictly inside a worked span: a date on a segment's first or last day, or in a gap, does nothing.
Since 3.20.0 resumeAt must fall after at and no later than that segment's last day; anything else is rejected with a console warning and the task is left unchanged. With a day-only format (like the YYYY-MM-DD here) the end day is worked, so resumeAt may be that last day, leaving a one-day remainder: splitTask('t1', '2026-06-09', { resumeAt: '2026-06-12' }) is accepted. With a format that carries time the end is exclusive, so resumeAt must be before it. Before 3.20.0 a resumeAt past the segment end produced a backwards segment, and one that was not after at produced overlapping segments.
The task keeps its finish date. A split takes worked time out of the task; it does not push the end out. In the example t1 still ends on 06-12. To show a slip, where the work resumes later and finishes later, write the new segments yourself:
gantt.updateTask('t1', {
segments: [
{ start: '2026-06-01', end: '2026-06-04' },
{ start: '2026-06-08', end: '2026-06-09' },
{ start: '2026-06-14', end: '2026-06-15' }, // the last two days resume on the 14th, so it now finishes on the 15th
],
})
splitTask() routes through updateTask, so it runs beforeTaskUpdate and is undoable; since 3.20.0 it also emits taskUpdate and taskUpdateSuccess (with source: 'api'). It is a no-op on milestones and summary bars.
Merge a task back into one contiguous bar by clearing its segments:
gantt.updateTask('t1', { segments: [] })
Since 3.20.0 a task given exactly one segment, in series or through updateTask, is stored as a plain task: the segment sets startTime and endTime, and the segments field is not kept. So updateTask('t1', { segments: [{ start: '2026-06-01', end: '2026-06-15' }] }) turns a split task back into a normal one with those dates, and getTask('t1').segments is then undefined.
Query whether a task is currently split:
if (gantt.isSplit('t1')) { /* ... */ }
React example
import { ApexGanttChart } from 'react-apexgantt'
import type { TaskInput } from 'react-apexgantt'
// startTime / endTime are derived from the segments (optional in TaskInput since 3.20.0)
const tasks: TaskInput[] = [
{
id: 'build',
name: 'Build',
segments: [
{ start: '2026-06-01', end: '2026-06-04' },
{ start: '2026-06-08', end: '2026-06-12' },
],
},
]
export default function SplitTaskGantt() {
return (
<ApexGanttChart
tasks={tasks}
options={{ inputDateFormat: 'YYYY-MM-DD' }}
height="400px"
/>
)
}
Related
- Task Management for the full CRUD API.
- Methods reference for
splitTask()andisSplit().