本节介绍了一组选择器,用于通过指定任务的开始日期和持续天数来设置任务的持续时间。
gantt.config.lightbox.sections=[
{name:"description", height:70, map_to:"text", type:"textarea", focus:true},
{name:"time", height:72, map_to:"auto", type:"duration"} ];
Related sample: Basic initialization
默认情况下,lightbox 包含一个 duration 控件。如需添加更多控件,请按照以下步骤操作:
1) 向 lightbox 配置中添加一个新分区:
gantt.config.lightbox.sections=[
{name:"description", height:70, map_to:"text", type:"textarea",focus:true},
{name:"time2", height:72, map_to:"auto", type:"duration"}, {name:"time", height:72, map_to:"auto", type:"duration"}
];
2) 为新分区定义标签:
gantt.locale.labels.section_time2 = "实际持续时间";
以下是 time 控件常用的主要属性(完整列表见 这里):
可以通过 time_format 属性自定义“时间区间”分区中的选择器(参见 日期格式规范):
Adding the time selector to the 'Time period' section
gantt.config.lightbox.sections = [
{name:"description", height:38, map_to:"text", type:"textarea", focus:true},
{name:"time",type:"duration",map_to:"auto",time_format:["%d","%m","%Y","%H:%i"]}];
time_format 数组中允许的元素包括:
你可以在数组中调整这些元素的顺序或省略某些元素,但数据格式本身不能更改。
例如,以下是一些变体:
// 时间在前
time_format:["%H:%i", "%m", "%d", "%Y"]
// 月份在前
time_format:["%m","%d", "%Y", "%H:%i"]
// 省略年份选择器
time_format:["%H:%i", "%m", "%d"]
// 错误用法
time_format:["%H:%i", "%M", "%d", "%Y"] // "%m" 被 "%M" 替换
通常,time 和 duration 控件通过将 map_to 设置为 "auto"(map_to:"auto")来关联到所需的 'start_date' 和 'end_date' 属性。
如需将控件关联到自定义日期属性而非 'start_date' 和 'end_date',可为 map_to 属性使用对象:
gantt.config.lightbox.sections = [
{name: "description", height: 72, type: "textarea", map_to:"text", focus: true},
{name: "time", height: 72, type: "duration", map_to:"auto"},
{name: "baseline", height: 72, type: "duration", map_to:{start_date:"planned_start",end_date:"planned_end"}} ];
Related sample: Display baselines
map_to 对象支持以下属性:
如果省略某个属性,控件将默认关联到相应的必填日期属性。
你可以通过在 lightbox 分区配置中设置 type:"duration_optional" 和 button: true 来切换持续时间分区的可见性:
gantt.config.lightbox.sections = [
{name: "description", height: 70, map_to: "text", type: "textarea", focus: true},
{name: "time", map_to: "auto", button: true, type: "duration_optional"} ];
同时,为切换按钮的两种状态定义标签:
gantt.locale.labels.time_enable_button = '计划';
gantt.locale.labels.time_disable_button = '取消计划';
分区旁会出现一个切换按钮,允许你切换其可见性。当可见时,该分区的行为与 type:"duration" 分区一致。
如果关闭按钮,分区会消失但不会立即生效。保存后,通过 map_to 映射到持续时间控件的任务属性将被设置为 null
。
gantt.getTask(1);
// 示例返回值
{
id: '1', text: 'Task #1', unscheduled: true,
duration: 0, parent: '10',
end_date: null, start_date: null,
...
}
此功能适用于将任务标记为未计划,或直接通过 UI 管理无基线的任务。请参见相关示例:
Related sample: Unscheduled tasks
Back to top