该控件提供一个下拉选择框,用于更改任务的父任务。它会加载甘特图中展示的所有任务,并支持应用过滤规则以及自定义选项的显示方式。除此之外,其使用方式与 Select 控件 控件相同。
gantt.config.lightbox.sections = [
{name:"description", height:38, map_to:"text", type:"textarea", focus:true},
{name:"parent", type:"parent", allow_root:"true", root_label:"No parent"}, {name:"time", height:72, type:"time", map_to:"auto"}
];
Related sample: Parent selector
要在 lightbox 中包含 parent 控件,需完成以下步骤:
1) 在 lightbox 配置中添加一个 section:
gantt.config.lightbox.sections = [
{name:"description", height:38, map_to:"text", type:"textarea",focus:true},
{name:"parent", type:"parent", allow_root:"true", root_label:"No parent"}, {name:"time", height:72, type:"duration", map_to:"auto"}
];
2) 为该 section 定义标签:
gantt.locale.labels["section_parent"] = "Parent task";
Related sample: Parent selector
以下是 parent 控件常用的一些主要属性(完整列表请参见 这里):
如需控制 parent 控件中显示哪些选项,可使用 filter 属性:
过滤,仅显示第一级任务
gantt.config.lightbox.sections = [
{name:"description", height:38, map_to:"text", type:"textarea", focus:true},
{name:"parent", type:"parent", filter:function(id, task){ if(task.$level > 1){ return false; }else{ return true; } }},
{name:"time", height:72, type:"time", map_to:"auto"}
];
Related sample: Parent selector
filter 函数接收两个参数:
返回值:
如需对 parent 控件中的选项进行排序,可使用 sort 属性:
按标题长度对任务排序
function sortByLength(a,b){
a = a.text.length();
b = b.text.length();
return a>b?1:(a<b?-1:0);
};
gantt.config.lightbox.sections = [
{name:"description", height:38, map_to:"text", type:"textarea", focus:true},
{name:"parent", type:"parent", sort:sortByLength}, {name:"time", height:72, type:"time", map_to:"auto"}
];
sort 函数用于比较相邻的两个选项,并返回:
如需自定义 parent 控件中选项的显示方式,可使用 template 属性:
gantt.config.lightbox.sections = [
{name:"description", height:38, map_to:"text", type:"textarea", focus:true},
{name:"parent", type:"parent", template(start,end,ev){ var title = ev.id+"."+ev.text; return title; }}, {name:"time", height:72, type:"time", map_to:"auto"}
];
template 函数接收三个参数:
返回值为该控件下拉选项的显示内容。
如果未设置 'template' 属性,选项将根据 task_text 中的模板进行格式化。