4、Gantt 任务节点部分
1、获取任务节点
1 gantt.addTask({ 2 id:7, 3 text:"Task #5", 4 start_date:"02-09-2013", 5 duration:28 6 }, "pr_2"); 7 8 gantt.getTask(7); 9 //->{id:7, text:"Task #5", start_date:"02-09-2013", duration:28, 10 // parent:"pr_2", $source:[1,5], $target:[8,13], ...}
2、返回下一项的 id(无论嵌套级别如何:相同或不同)
1 var tasks = { 2 data:[ 3 {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, 4 open:true}, 5 {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8, 6 parent:"p_1"}, 7 {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8, 8 parent:"p_1"} 9 ] 10 }; 11 gantt.init("gantt_here"); 12 gantt.parse(tasks); 13 gantt.getNext("p_1"); -> "t_1" 14 gantt.getNext("t_1"); -> "t_2" 15 gantt.getNext("t_2"); -> null
3、返回父任务的 id
1 var tasks = { 2 data:[ 3 {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, 4 open:true}, 5 {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8, 6 parent:"p_1"}, 7 {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8, 8 parent:"p_1"} 9 ] 10 }; 11 gantt.init("gantt_here"); 12 gantt.parse(tasks); 13 14 gantt.getParent("t_1"); //-> "p_1" 15 gantt.getParent("p_1"); //-> 0 (the default root id)
4、返回任务栏的 HTML 元素
1 gantt.addTask({ 2 id:10, 3 text:"Task #5", 4 start_date:"02-09-2013", 5 duration:28 6 }, "project_2"); 7 8 gantt.getTaskNode(10);//-><div task_id="2" class="gantt_task_line" …>…</div>
5、返回表格中任务行的 HTML 元素
1 var taskId = gantt.addTask({ 2 id:10, 3 text:"Task #5", 4 start_date:"02-09-2013", 5 duration:28 6 }, "project_2"); 7 8 gantt.getTaskRowNode(10);//-><div class="gantt_row" task_id="2">…</div>
6、按指定条件查找任务
1 // simple search 2 var userTasks = gantt.getTaskBy("user_id", 5); 3 4 // (task: object) => boolean 5 var userTasks = gantt.getTaskBy(function(task){ 6 return task.user_id == 5 || !task.user_id; 7 }); 8 9 var userTasks = gantt.getTaskBy(task => task.user_id == 5);
7、通过 WBS 代码返回任务
1 var task = gantt.getTaskByWBSCode("1.2"); 2 // => {id:"t1", text:"Task #1, unscheduled: true, duration: 1, …}
8、返回任务的 WBS 代码(大纲编号)
1 gantt.init("gantt_here"); 2 3 gantt.parse({ 4 "data":[ 5 {"id":1, "text":"Project #1", "start_date":"28-03-2013", "duration":"11", 6 "parent":"0", "open": true}, 7 {"id":2, "text":"Task #1", "start_date":"01-04-2013", "duration":"18", "parent":"1"}, 8 {"id":3, "text":"Task #2", "start_date":"02-04-2013", "duration":"8", "parent":"1"} 9 ], 10 "links":[] 11 }); 12 13 var wbs_code = gantt.getWBSCode(gantt.getTask(3)) // -> returns "1.2"
9、通过其全局任务索引返回任务
1 var globalTaskIndex = gantt.getGlobalTaskIndex(19); // -> 10 2 3 var task = gantt.getTaskByIndex(10); 4 // -> {id:"19", text:"Task name", type:"project", order:"10", progress:0.4, …}
10、返回指定时间段内发生的任务的集合
1 var tasks = gantt.getTaskByTime(new Date(2013,3,10),new Date(2013,4,10)); 2 for (var i=0; i<tasks.length; i++){ 3 alert(tasks[i].text); 4 } 5 // or 6 var tasks = gantt.getTaskByTime();//returns all tasks
11、返回指定父分支的一级子任务
1 var tasks = { 2 data:[ 3 {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, 4 open:true}, 5 {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8, 6 parent:"p_1"}, 7 {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8, 8 parent:"p_1"} 9 ] 10 }; 11 gantt.init("gantt_here"); 12 gantt.parse(tasks); 13 14 gantt.getChildren("p_1");//->["t_1", "t_2"]
12、检查当前是否选择了指定的任务
1 gantt.templates.task_class = 2 gantt.templates.grid_row_class = 3 gantt.templates.task_row_class = function (start, end, task) { 4 if (gantt.isSelectedTask(task.id)) 5 return "gantt_selected"; 6 };
13、检查指定的任务是否存在
添加新任务
1 gantt.addTask({ 2 id:10, 3 text:"Task #5", 4 start_date:"02-09-2013", 5 duration:28 6 }, "project_2"); 7 8 gantt.isTaskExists(10); // ->true
14、检查指定任务当前是否在甘特图中呈现
1 var tasks = { 2 data:[ 3 {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, 4 open:true}, 5 {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8, 6 parent:"p_1"}, 7 {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8, 8 parent:"p_1"} 9 ] 10 }; 11 gantt.init("gantt_here"); 12 gantt.parse(tasks); 13 14 gantt.isTaskVisible("t_1"); // ->true
15、返回时间刻度的配置
1 gantt.getScale();
16、获取甘特图中当前加载的任务数
1 gantt.getTaskCount();
17、获取分支中任务的索引
1 var tasks = { 2 data:[ 3 {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, 4 open:true}, 5 {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8, 6 parent:"p_1"}, 7 {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8, 8 parent:"p_1"} 9 ] 10 }; 11 gantt.init("gantt_here"); 12 gantt.parse(tasks); 13 14 var taskIndex = gantt.getTaskIndex("t_1"); // -> 0 15 var globalTaskIndex = gantt.getGlobalTaskIndex("t_1"); // -> 1
18、返回任务的类型
1 var type = gantt.getTaskType(gantt.getTask(12));
19、返回数据存储的配置对象
1 var tasksStore = gantt.getDatastore("task"); 2 //获取所有的ID 3 gantt.getDatastore("task").fullOrder 4 //获取所有节点 5 gantt.getDatastore("task").pull
20、返回当前选定任务的数组
1 gantt.getSelectedTasks(); 2 // 这个方法是在multiselect扩展中定义的,所以需要激活multiselect插件。 3 gantt.plugins({ 4 multiselect: true 5 }); 6 gantt.config.multiselect = true; // 多选
21、返回所选任务的 id
1 var tasks = { 2 data:[ 3 {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, open:true}, 4 {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8, parent:"p_1"}, 5 {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8, parent:"p_1"} 6 ] 7 }; 8 9 gantt.init("gantt_here"); 10 gantt.parse(tasks); 11 12 gantt.selectTask("t_1"); 13 gantt.getSelectedId(); // -> "t_1"
22、选择指定的任务
1 var tasks = { 2 data:[ 3 {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, open:true}, 4 {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8, parent:"p_1"}, 5 {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8, parent:"p_1"} 6 ] 7 }; 8 9 gantt.init("gantt_here"); 10 gantt.parse(tasks); 11 12 gantt.selectTask("t_1"); 13 14 // 该方法调用onTaskSelected事件。 15 gantt.attachEvent("onTaskSelected", function(id){ 16 //any custom logic here 17 });
23、检查指定项目是否有子任务
1 var tasks = { 2 data:[ 3 {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, 4 open:true}, 5 {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8, 6 parent:"p_1"}, 7 {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8, 8 parent:"p_1"} 9 ] 10 }; 11 gantt.init("gantt_here"); 12 gantt.parse(tasks); 13 14 gantt.hasChild("p_1"); //-> true gantt.hasChild("t_1"); //-> false
24、获取屏幕上可见的任务数(未折叠的任务)
1 gantt.getVisibleTaskCount();
25、更新指定的任务
1 var taskId = gantt.addTask({ 2 id:10, 3 text:"Task #10", 4 start_date:"02-04-2013", 5 duration:8, 6 parent:1 7 }); 8 9 gantt.getTask(taskId).text = "Task #13"; //changes task's data 10 gantt.updateTask(taskId); //renders the updated task 11 12 gantt.attachEvent("onAfterTaskUpdate", function(id,item){ 13 //any custom logic here 14 });
26、打开具有指定 id 的分支
1 var tasks = { 2 data:[ 3 {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18}, 4 {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8, 5 parent:"p_1"}, 6 {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8, 7 parent:"p_1"} 8 ] 9 }; 10 11 gantt.init("gantt_here"); 12 gantt.parse(tasks); 13 gantt.open("p_1"); 14 15 gantt.attachEvent("onTaskOpened", function(id) { 16 //any custom logic here 17 });
27、关闭具有指定 id 的分支
1 var tasks = { 2 data:[ 3 {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, 4 open:true}, 5 {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8, 6 parent:"p_1"}, 7 {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8, 8 parent:"p_1"} 9 ] 10 }; 11 gantt.init("gantt_here"); 12 gantt.parse(tasks); 13 14 gantt.close("p_1"); 15 16 gantt.attachEvent("onTaskClosed", function(id) { 17 alert("You've closed a branch with id="+id); 18 });
28、删除指定的任务
1 gantt.addTask({ 2 id:10, 3 text:"Project #1", 4 start_date:"02-09-2013", 5 duration:28 6 }); 7 8 gantt.deleteTask(10); 9 gantt.attachEvent("onBeforeTaskDelete", function(id,item){ 10 //any custom logic here 11 return true; 12 }); 13 gantt.attachEvent("onAfterTaskDelete", function(id,item){ 14 //any custom logic here 15 });

浙公网安备 33010602011771号