从旧版本迁移
9.1 -> 10.0
從 GPL 版本遷移到社群版 Community (MIT)
从 GPL 版迁移到 Community (MIT) 版
自 v10 起,DHTMLX Gantt 的免费版为 Community 版,在 MIT 许可证下分发。它取代了同一 dhtmlx-gantt 包之前的免费 GPL 版本。GPL v2 仍适用于之前的免费版本(v9.x 及更早版本),这些版本仍在 main GitHub repository 的专门分支中可用,但不再 actively maintained。
自 v10 起,DHTMLX Gantt 的免费版为 Community 版,在 MIT 许可证下分发。它取代了同一 dhtmlx-gantt 包之前的免费 GPL 版本。GPL v2 仍适用于之前的免费版本(v9.x 及更早版本),这些版本仍在 main GitHub repository 的专门分支中可用,但不再积极维护。
要将现有项目从 GPL 版迁移到 Community 版:
- 检查软件包版本。
dhtmlx-ganttv10 及更高版本为 Community (MIT) 版;v9.x 及更早为 GPL 版。 - 更新许可证说明,若在项目中引用了 Gantt 的许可证——免费版现在是 MIT,而不是 GPL。
- 在运行时验证许可证值 -
gantt.license对 Community 版返回"mit"(之前的免费版返回的是"gpl") - 测试导出行为。 在线导出服务对免费导出仍然会添加水印;此行为保持不变,与 GPL 许可证不再绑定(导出服务是独立产品)。
- 查看功能差异。 Community 版不是旧 GPL 版的严格超集。它 新增 项目(摘要任务)、里程碑、自定义任务类型,以及每页支持多个 Gantt 实例的能力,但 移除了 撤销/重做、标记、多选、未排程任务、新任务占位行、工作日历和 WBS 码。完整功能对比请参见 Community vs PRO Library Versions。
XSS protection in framework wrappers
自 v10.0 起,React Gantt、Vue Gantt 及 Angular Gantt 封装默认对来自用户 提供的模板函数的字符串值进行清理,而不是直接将其作为原始 HTML 插入。这可防止通过模板渲染未经过净化的数据导致的 XSS 漏洞。
它适用于:
- 通过
templates属性传递的函数 config.columns[].template函数config.scales[].format函数
默认情况(htmlTemplatePolicy="basic-sanitize")返回的 HTML 采用白名单净化:保留常见的格式标签(<b>、<span>、<div> 等)、class、受限的一组内联样式、data-* 属性以及具有安全 src 的 <img/>,同时移除 <script>、内联事件处理程序和危险的 URL。返回简单标记的模板仍然可以工作;只有不安全的结构会被删除。
还原以前的 raw-HTML 行为
将 htmlTemplatePolicy 属性设为 "unsafe-html" 以按以前的方式原样渲染模板字符串,无需处理:
<ReactGantt htmlTemplatePolicy="unsafe-html" /* ... */ />
<VueGantt htmlTemplatePolicy="unsafe-html" /* ... */ />
<dhx-gantt htmlTemplatePolicy="unsafe-html" /* ... */></dhx-gantt>
针对单个模板的原始 HTML
用 allowRawHTML 包裹单个模板,以绕过该模板的净化——请自 行使用导出的 escapeHTML 助手对任意用户数据进行清理:
import { allowRawHTML, escapeHTML } from "@dhx/react-gantt";
// 或 "@dhx/vue-gantt" / "@dhx/angular-gantt"
<ReactGantt
templates={{
task_text: allowRawHTML((start, end, task) => `<b>${escapeHTML(task.text)}</b>`)
}}
/>
自定义清理器或文本渲染
使用 htmlTemplatePolicy={{ mode: "sanitize", sanitize }} 来接入诸如 DOMPurify 之类的清理器,或使用 "escape" 将模板字符串渲染为纯文本。更多信息请参阅 App security。
Auto-scheduling engine update
v10.0 内置了经过重新设计的自动排程引擎。它修复了若干长期存在的错误,主要集中在松弛时间(Slack)计算以及在启用 move_projects 时对项目(汇总任务)的排程。 公共 API 与可见行为保持不变,除了先前工作不正确的情况。可能影响现有代码的变更如下所列。
新引擎默认为默认引擎。如果在过渡期间需要切换回旧的引擎,请使用如下的退出标志:
gantt.config.auto_scheduling = {
enabled: true,
_engine: "v1", // previous scheduling engine
_analysis_engine: "v1" // previous slack / critical path calculation
};
这些标志是过渡性的,将在 v10.1 中移除,因此请在此之前完成迁移。
行为变更
| 领域 | 在 v9.x 的情况 | 自 v10.0 起 | 应该怎么做 |
|---|---|---|---|
重复调用 gantt.autoSchedule() | 在混合使用若干日历的项目上,任务可能向前移动 | 在未改动的数据上再次运行自动排程将保留相同日期 | 无需操作 |
| Slack 与关键路径值 | 当 move_projects / gap_behavior 改变时可能变化 | 仅依赖数据,与排程模式选项无关 | 无需操作 |
针对不参与计算的任务的 getTotalSlack() / getFreeSlack()(依赖环、已完成任务) | 可能返回 undefined | 返回 0 | 更新将 undefined 与 0 区分对待的代码 |
getSlack(task1, task2) | 仅对直接相连的任务准确 | 跨链接任务的数值更准确;未链接对的数值保持不变 | 更推荐使用 getTotalSlack / getFreeSlack |
约束与偏好驱动移动的 onBeforeTaskAutoSchedule / onAfterTaskAutoSchedule 参数 | link 和源任务参数可能被设置 | 对此类移动,这些参数为 null | 在假设 link 参数总是被设置的监听器中增加对 null 的检查 |
含 gap_behavior: "preserve" 的 Start-to-Finish 链接 | 后继任务总是尽快调度(如同 "compress") | 将遵循 gap_behavior 选项 | 无需操作——这是修正后的行为 |
使用 move_projects: true 移动项目 | 子孙的自身约束可能悄悄地把整个项目保持在原地 | 整个项目一起移动;若子孙的约束冲突,会通过 onAutoScheduleConflict 报告 | 可选地监听 onAutoScheduleConflict 以暴露冲突 |
新的事件与配置
- onAutoScheduleConflict - 在排程期间发现的每个冲突时触发。
- onAutoScheduleNoConverge - 当排程无法对稳定结果达成一致时触发。
- strict_calendar - 可选开启项(默认
false),在任务落在自家非工作时间时会发出报告。
已知限制
- 当一个约束日期(例如 must-finish-on 或 start-no-later-than)落在自定义日历的非工作时间内,任务会获得一个受约束的正确日期,但其存储的
end_date(按 start + duration 计算)可能与约束日期完全一致地匹配不上。将触发 onAutoScheduleConflict 事件,便于你对不匹配做出反应。若要严格遵守约束,请使用工作时间包括该约束日期的日历。 - 在数据解析后直接在代码中对项目(汇总任务)设置约束类型,可能在解析过程中被覆盖。请在加载的数据中设置此类约束,或通过 lightbox / 内联编辑器进行设置。
Date helper changes
Interval-start helpers are now pure
gantt.date 的区间起始辅助函数 - day_start、week_start、month_start、quarter_start、year_start、hour_start、minute_start,以及 date_part - 现在返回一个新的 Date,不再修改传给它们的日期。
返回值保持不变,因此仅对依赖就地变更并忽略返回值的代码需要更新:
// before v10.0 - relied on day_start mutating `date`
gantt.date.day_start(date);
// since v10.0 - use the returned date
date = gantt.date.day_start(date);
Single date parser and the deprecated csp config
Gantt 不再提供基于 new Function 的“快速”日期解析器。现在唯一的实现是 CSP-安全解析器,[csp](/api/config/csp) 配置不再影响日期格式化。
该选项仍然保留,并仍被 lightbox 视为一个安全环境提示,因此现有配置将继续工作。无需迁移——仅为日期格式设置的 gantt.config.csp 可以移除。
TypeScript: SerializedTask is now strictly serialized
SerializedTask 和 SerializedLink 类型现在仅描述 JSON 表单:
- 日期字段(
start_date、end_date、constraint_date、deadline、…)被标注为string。在 9.x 版本中它们是Date | string。 SerializedTask.id现已可选。
如果你将应用数据(例如 store、种子数组、演示数据)定义为 SerializedTask[] 但实际用 Date 对象填充,它将导致编译器报错,例如 "Type 'Date' is not assignable to type 'string'"。
请选取与数据实际保存的类型匹配的类型:
Task/Link- 运行时对象,日期为Date,并带有$前缀的字段(这是gantt.getTask()返回的对象)。SerializedTask/SerializedLink- 含string日期的 JSON(服务 器交换、持久化 JSON)。TaskInput- 你提供给 Gantt 的数据;日期可以是Date或string,并且每个字段(包括id)都是可选的。这通常是应用程序拥有的状态的正确类型。
// before v10 - SerializedTask accepted Date, so this compiled
const tasks: SerializedTask[] = [
{ id: 1, text: "Task #1", start_date: new Date(2026, 3, 1), duration: 5 }
];
// since v10 - use Task (Date dates), or TaskInput when the date form may vary
const tasks: TaskInput[] = [
{ id: 1, text: "Task #1", start_date: new Date(2026, 3, 1), duration: 5 }
];
TaskInput 是規範的輸入類型,取代了先前已棄用的 NewTask 別名(為了向後相容,仍然導出)。有關完整信息,請參閱資料模型
9.0 -> 9.1
v9.1 不会引入重大变更,但若干配置选项已被标记为 弃用,并建议 迁移到新的统一格式。 另请注意,先前被弃用的 subscales 配置选项已被删除。
Unified auto scheduling configuration
此前用于控制 "Automatische Terminplanung" 行为的多个属性已被弃用,取而代之的是统一的 auto_scheduling 配置对象。
// before v9.1
gantt.config.auto_scheduling = true;
gantt.config.auto_scheduling_compatibility = true;
gantt.config.auto_scheduling_strict = true;
gantt.config.auto_scheduling_initial = false;
// since v9.1
gantt.config.auto_scheduling = {
enabled: true,
apply_constraints: false,
gap_behavior: "compress",
schedule_on_parse: false
};
为保持向后兼容,这些已弃用的属性仍然可以使用,但建议切换到新的对象格式。
以下选项已弃用:
- auto_scheduling_initial
- auto_scheduling_compatibility
- auto_scheduling_descendant_links
- auto_scheduling_move_projects
- auto_scheduling_project_constraint
- auto_scheduling_strict
- auto_scheduling_use_progress
Mapping of deprecated configs to the unified object
gantt.config.auto_scheduling_initial->schedule_on_parsegantt.config.auto_scheduling_descendant_links->descendant_linksgantt.config.auto_scheduling_move_projects->move_projectsgantt.config.auto_scheduling_project_constraint->project_constraintgantt.config.auto_scheduling_use_progress->use_progressgantt.config.auto_scheduling_compatibility = true->apply_constraints: falsegantt.config.auto_scheduling_compatibility = false->apply_constraints: truegantt.config.auto_scheduling_strict = true->gap_behavior: "compress"gantt.config.auto_scheduling_strict = false->gap_behavior: "preserve"
The obsolete subscales configuration option is deleted
请注意,在 v6.2 中被弃用的 subscales 配置选项已在 v9.1 中删除。
8.0 -> 9.0
v9.0 更新引入了若干重大变更。
皮肤切换为 CSS 变量
CSS 皮肤(主题)已完全重构,现在采用 CSS 变量实现。虽然组件的 HTML 结构和 CSS 类名大部分保持不变,但为旧版本 Gantt 编写的 CSS 样式在 v9.0 中可能无法如预期生效。
例如,以下样式用于根据任务优先级着色:
<style>
/* 覆盖边框/进度颜色的通用样式 */
.gantt_task_line{
border-color: rgba(0, 0, 0, 0.25);
}
.gantt_task_line .gantt_task_progress {
background-color: rgba(0, 0, 0, 0.25);
}
/* 高优先级 */
.gantt_task_line.high {
background-color: #03A9F4;
}
.gantt_task_line.high .gantt_task_content {
color: #fff;
}
/* 中优先级 */
.gantt_task_line.medium {
background-color: #f57730;
}
.gantt_task_line.medium .gantt_task_content {
color: #fff;
}
/* 低优先级 */
.gantt_task_line.low {
background-color: #e157de;
}
.gantt_task_line.low .gantt_task_content {
color: #fff;
}
</style>
从 v9.0 开始,可以使用以下样式实现相同效果:
<style>
/* 高优先级 */
.gantt_task_line.high {
--dhx-gantt-task-background: #d96c49;
--dhx-gantt-task-color: #fff;
}
/* 中优先级 */
.gantt_task_line.medium {
--dhx-gantt-task-background: #f57730;
--dhx-gantt-task-color: #fff;
}
/* 低优先级 */
.gantt_task_line.low {
--dhx-gantt-task-background: #fff;
--dhx-gantt-task-color: #fff;
}
</style>
可在 스킨 커스터마이제이션 页面查看可用变量。
迁移时很可能需要更新现有 CSS 以达到所需设计效果。
单一 CSS 文件
所有主题现在都集成在一个 dhtmlxgantt.css 文件中。
如需激活特定皮肤,请使用 gantt.skin 属性:
gantt.skin = "material";
或使用 setSkin 方法:
gantt.setSkin("material");
请注意,gantt.setSkin() 会重新渲染 Gantt。
如果你使用的是 terrace 以外的皮肤,迁移步骤如下:
- 替换皮肤的 CSS 文件为
dhtmlxgantt.css文件:
<!-- 旧 -->
<link rel="stylesheet" href="./codebase/dhtmlxgantt_material.css" type="text/css">
<!-- 新 -->
<link rel="stylesheet" href="./codebase/dhtmlxgantt.css" type="text/css">
- 在 JavaScript 中启用所需皮肤:
gantt.setSkin("material");
gantt.init("gantt_here");
内置基线、截止日期和约束支持
此前,添加基线需要通过 gantt.addTaskLayer API 手动实现。从 Gantt 9.0 起,已内置对基线实体、截止日期和任务约束的支持。
如果需要关闭默认设置,手动渲染基线和截止日期,可以使用相关配置项:baselines 与 deadlines:
// 禁用内置基线功能
gantt.config.baselines = false;
// 禁用内置截止日期功能
gantt.config.deadlines = false;
任务约束的内置显示也可通过扩展的 auto_scheduling 配置关闭:
gantt.config.auto_scheduling = {
enabled: true,
show_constraints: false /*!*/
};
这样会关闭任务约束的默认显示,但仍保留自动调度功能。
时间线中的粘性标签
自 v9.0 起,时间刻度标签默认为粘性。即标签在滚动时始终可见,直到自然滚动出视口。在旧版本中,标签居中显示在单元格内,滚动时不会保持可见。
如需恢复旧行为并禁用粘性标签,可将 scale 对象的 sticky 属性设为 false:
gantt.config.scales = [
{unit: "year", step: 1, format: "%Y", sticky: false},
{unit: "month", step: 1, format: "%F", sticky: false},
{unit: "day", step:1, format: "%j", sticky: false}
];
Promise 实现
Bluebird 库已从 Gantt 包中移除。Promise 现在使用原生 Promise 实现。
Lightbox 调整大小
自 v9.0 起,resizeLightbox 方法已弃用并从 Gantt 代码中移除。现在 lightbox 的尺 寸调整已自动实现,无需手动调用。 请注意,如果你的配置中包含 resizeLightbox() 方法,应将其移除以避免报错。
7.1 -> 8.0
资源分配
在早期版本的 DHTMLX Gantt 中,资源分配的变更作为任务对象的属性发送到后端,这在某些情况下使后端 API 集成变得更复杂。
从 DHTMLX Gantt v8.0 起,对资源及资源分配的变更可通过 dataProcessor 路由。详见 Routing CRUD actions of resources and resource assignments 部分。
导出服务
自 v8.0 起,导入/导出功能已集成到 gantt 库中。
因此,如果你已在页面中包含 https://export.dhtmlx.com/gantt/api.js 以启用在线导出服务,例如:
<script src="codebase/dhtmlxgantt.js"></script>
<script src="https://export.dhtmlx.com/gantt/api.js"></script>
则需移除该文件,并通过 gantt.plugins 方法启用 export_api 扩展:
gantt.plugins({
export_api: true
});
已弃用的类名
自 v8.0 起,以下已弃用的类名被移除并替换为新的类名:
- ".dhtmlx-info" -> ".gantt-info"
- ".dhtmlx-error" -> ".gantt-info"
- ".dhtmlx_popup_title" -> ".gantt_popup_title"
- ".dhtmlx_popup_text" -> ".gantt_popup_text"
- ".dhtmlx_popup_controls" -> ".gantt_popup_controls"
- ".dhtmlx_ok_button" -> ".gantt_ok_button"
- ".dhtmlx_click_me_button" -> ".gantt_click_me_button"
- ".dhtmlx_popup_button" -> ".gantt_popup_button"
- ".dhtmlx_modal_box" -> ".gantt_modal_box"
- ".dhtmlx-" + config.type -> ".gantt-" + config.type
- ".dhtmlx_" + btn.label.toLowerCase() + "button" -> **".gantt" + btn.label.toLowerCase() + "_button"**
7.0 -> 7.1
7.1 版本未引入任何需要修改现有代码的重大变更。
里程碑渲染方式有细微视觉变化,如有需要可通过代码还原。对于使用资源面板的大型项目,由于资源分配新逻辑,可能会出现性能下降问题,可通过禁用不需要的逻辑进行优化。
里程碑
与旧版本相比,里程碑元素的尺寸已更改,使其高度与常规条形一致。
如需让里程碑外观与旧版本一致,可通过 bar_height 属性调整里程碑元素高度:
{
id:23, text:"Mediate milestone", start_date:"13-04-2018",
type:"milestone", parent:"15", bar_height: 35
}
资源分配
7.1 版本为资源分配增加了复杂逻辑,允许指定资源分配的日期,并可通过 DataStore 操作资源分配。 该更改不会影响现有代码,但可能会对资源计算带 来明显性能开销。
如果不需要为任务的特定日期分配资源,可通过 process_resource_assignments 配置关闭新功能以提升性能:
gantt.config.process_resource_assignments = false;
任务对象的新可选属性
以下任务对象属性现在被 gantt 处理,并影响任务显示:
- "task.row_height"
- "task.bar_height"
- "task.hide_bar"
- "task.rollup"
如果你有同名的自定义属性,请重命名以避免冲突。