本功能仅在 PRO 版本中提供。
在甘特图中有三种预定义的任务类型可供展示(你也可以创建自定义类型):
要分配任务类型,请在数据项中使用 type 属性(对应 types 对象中的值):
在数据集中指定任务类型
var data = {
task:[
{id:1, text:"Project #1", type:"project", open:true}, {id:2, text:"Task #1", start_date:"12-04-2020", duration:3, parent:1},
{id:3, text:"Alpha release", type:"milestone", parent:1, start_date:"14-04-2020"}, {id:4, text:"Task #2", start_date:"17-04-2020", duration:3, parent:1}],
links:[]
};
Related sample: Projects and milestones
默认情况下,dhtmlxGantt 会创建常规任务(即 type="task" 的任务)。
指定常规任务
var data = {
tasks:[{id:2, text:"Task #1", start_date:"12-04-2020", duration:3}], links:[]
};
// 或
var data = {
tasks:[{id:2, text:"Task #1", start_date:"12-04-2020", duration:3, type:"task"}], links:[]
};
Related sample: Projects and milestones
被标记为 type="task" 的任务具有以下特性:
项目任务的时间跨度为其最早子任务的开始时间到最晚子任务的结束时间。
项目任务与常规任务的主要区别在于,项目任务的工期取决于其子任务,并会随之更新。
指定项目任务
var data = {
tasks:[
{id:1, text:"Project #1", type:"project", open:true}, {id:2, text:"Task #1", start_date:"12-04-2020", duration:3, parent:1},
{id:3, text:"Alpha release", type:"milestone", parent:1,
start_date:"14-04-2020"}],
links:[]
};
Related sample: Projects and milestones
type="project" 的任务具有以下特点:
如需启用项目任务的添加,请参见 Milestones。启用里程碑创建后,用户也可添加项目任务。
里程碑 是工期为零的任务,用于突出显示项目中的关键日期(详细信息)。
指定里程碑
var data = {
tasks:[
{id:1, text:"Project #1", type:"project", open:true},
{id:2, text:"Task #1", start_date:"12-04-2020", duration:3, parent:1},
{id:3, text:"Alpha release", type:"milestone", parent:1, start_date:"14-04-2020"}], links:[]
};
Related sample: Projects and milestones
type="milestone" 的任务具有以下特性:
如需启用里程碑创建,请参见 Milestones。
每种任务类型有其独特属性,因此详情表单(lightbox)可针对不同类型单独配置。 相关配置存储在 lightbox 对象中。
包括以下内容:
默认配置如下:
gantt.config.lightbox.sections = [
{name: "description", height: 70, map_to: "text", type: "textarea", focus: true},
{name: "time", type: "duration", map_to: "auto"}
];
gantt.config.lightbox.project_sections= [
{name: "description", height: 70, map_to: "text", type: "textarea", focus: true},
{name: "type", type: "typeselect", map_to: "type"},
{name: "time", type: "duration", readonly: true, map_to: "auto"}
];
gantt.config.lightbox.milestone_sections= [
{name: "description", height: 70, map_to: "text", type: "textarea", focus: true},
{name: "type", type: "typeselect", map_to: "type"},
{name: "time", type: "duration", single_date: true, map_to: "auto"}
];
当在选择控件中更改任务类型时,lightbox 会动态切换至相应配置。
你也可以创建自定义任务类型并为其定义 lightbox 结构。
更多 lightbox 配置内容请参见 配置编辑表单 章节。
所有任务类型均定义在 types 对象中。
要添加自定义任务类型,一般需遵循以下步骤:
例如,添加一个名为 meeting 的新类型,其行为类似常规任务,但拥有独特颜色和自定义 lightbox 输入:
如下定义新类型 meeting 及其 lightbox:
gantt.config.types.meeting = "type_id";
这里,“meeting”是为了代码可读性而设的名称。gantt.locale.labels.type_meeting = "Meeting";
gantt.config.lightbox.meeting_sections = [
{name:"title", height:20, map_to:"text", type:"textarea", focus:true},
{name:"details", height:70, map_to: "details", type: "textarea"},
{name:"type", type:"typeselect", map_to:"type"},
{name:"time", height:72, type:"time", map_to:"auto"}
];
gantt.locale.labels.section_title = "Subject";
gantt.locale.labels.section_details = "Details";
.meeting_task{
border:2px solid #BFC518;
color:#6ba8e3;
background: #F2F67E;
}
.meeting_task .gantt_task_progress{
background:#D9DF29;
}
gantt.templates.task_class = function(start, end, task){
if(task.type == gantt.config.types.meeting){
return "meeting_task";
}
return "";
};
gantt.templates.task_text = function(start, end, task){
if(task.type == gantt.config.types.meeting){
return "Meeting: <b>" + task.text + "</b>";
}
return task.text;
};
Related sample: Custom task type
如需更改现有任务类型的外观,可使用 type_renderers 选项。此功能允许你重写控制任务类型在页面上渲染方式的函数。
gantt.config.type_renderers["project"]=function(task, defaultRender){
var main_el = document.createElement("div");
main_el.setAttribute(gantt.config.task_attribute, task.id);
var size = gantt.getTaskPosition(task);
main_el.innerHTML = [
"<div class='project-left'></div>",
"<div class='project-right'></div>"
].join('');
main_el.className = "custom-project";
main_el.style.left = size.left + "px";
main_el.style.top = size.top + 7 + "px";
main_el.style.width = size.width + "px";
return main_el;
};
Back to top