该控件通过两个选择器设置任务的持续时间,可定义任务的开始和结束日期。
gantt.config.lightbox.sections=[
{name:"description", height:70, map_to:"text", type:"textarea", focus:true},
{name:"time", height:72, map_to:"auto", type:"time"} ];
要在 lightbox 中包含 time 控件,请按如下操作:
1) 在 lightbox 配置中添加一个 section:
gantt.config.lightbox.sections=[
{name:"description", height:70, map_to:"text", type:"textarea",focus:true},
{name:"period", height:72, map_to:"auto", type:"time"}, ];
2) 为该 section 分配一个标签:
gantt.locale.labels.section_period = "Time period";
以下是与 'time' 控件常用的一些关键属性(完整列表见 这里):
要自定义 "duration" 或 "time" section 中的选择器,请使用 time_format 属性(详见 日期格式规范):
向 'Time period' section 添加时间选择器
gantt.config.lightbox.sections = [
{name:"description", height:38, map_to:"text", type:"textarea", focus:true},
{name:"time",type:"time", 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: "deadline", height: 72, type: "time", map_to:{start_date:"planned_start",end_date:"planned_end"}} ];
Related sample: Displaying deadlines
map_to 的对象形式支持:
如果某个属性被省略,控件将使用对应的必需日期属性。
你可以通过在 lightbox section 配置中设置 type:"time_optional" 并加上 button: true 来控制 time section 的可见性:
gantt.config.lightbox.sections = [
{name: "description", height: 70, map_to: "text", type: "textarea", focus: true},
{name: "time", map_to: "auto", button: true, type: "time_optional"} ];
同时,为切换按钮的不同状态定义标签:
gantt.locale.labels.time_enable_button = 'Schedule';
gantt.locale.labels.time_disable_button = 'Unschedule';
section 旁边会出现一个切换按钮,可用来显示或隐藏该 section。当可见时,其行为与 type:"time" 相同。
如果按钮被切换关闭,section 会隐藏,但不会立即发生变化。点击 "Save" 后,通过 map_to 与 time 控件关联的任务属性会被设为 null
。
gantt.getTask(1);
// 返回值
{
id: '1', text: 'Task #1', unscheduled: true,
duration: 0, parent: '10',
end_date: null, start_date: null,
...
}
此功能可用于标记任务为未计划状态。参见相关示例:
Related sample: Unscheduled tasks
Back to top