4、Gantt 任务节点部分

  1. 获取任务节点
    https://docs.dhtmlx.com/gantt/api__gantt_gettask.html
gantt.addTask({
    id:7,
    text:"Task #5",
    start_date:"02-09-2013",
    duration:28
}, "pr_2");
 
gantt.getTask(7);
//->{id:7, text:"Task #5", start_date:"02-09-2013", duration:28, 
//   parent:"pr_2", $source:[1,5], $target:[8,13], ...}
  1. 返回下一项的 id(无论嵌套级别如何:相同或不同)
    https://docs.dhtmlx.com/gantt/api__gantt_getnext.html
在这里插入代码片
  1. 返回下一项的 id(无论嵌套级别如何:相同或不同)
    https://docs.dhtmlx.com/gantt/api__gantt_getparent.html
var tasks = {
  data:[
     {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, 
     open:true},
     {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8,
     parent:"p_1"},
     {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8,
     parent:"p_1"}
   ]
};
gantt.init("gantt_here");
gantt.parse(tasks);
 
gantt.getParent("t_1"); //-> "p_1" 
gantt.getParent("p_1"); //-> 0 (the default root id)
  1. 返回任务栏的 HTML 元素
    https://docs.dhtmlx.com/gantt/api__gantt_gettasknode.html
gantt.addTask({
    id:10,
    text:"Task #5",
    start_date:"02-09-2013",
    duration:28
}, "project_2");
 
gantt.getTaskNode(10);//-><div task_id=​"2" class=​"gantt_task_line" ​…​​>​​…​</div>​
  1. 返回表格中任务行的 HTML 元素
    https://docs.dhtmlx.com/gantt/api__gantt_gettaskrownode.html
var taskId = gantt.addTask({
    id:10,
    text:"Task #5",
    start_date:"02-09-2013",
    duration:28
}, "project_2");
 
gantt.getTaskRowNode(10);//-><div class=​"gantt_row" task_id=​"2">​…​</div>​
  1. 按指定条件查找任务
    https://docs.dhtmlx.com/gantt/api__gantt_gettaskby.html
// simple search
var userTasks = gantt.getTaskBy("user_id", 5);
 
// (task: object) => boolean
var userTasks = gantt.getTaskBy(function(task){
   return task.user_id == 5 || !task.user_id;
});
 
var userTasks = gantt.getTaskBy(task => task.user_id == 5);
  1. 通过 WBS 代码返回任务
    https://docs.dhtmlx.com/gantt/api__gantt_gettaskbywbscode.html
var task = gantt.getTaskByWBSCode("1.2");
// => {id:"t1", text:"Task #1, unscheduled: true, duration: 1, …}
  1. 返回任务的 WBS 代码(大纲编号)
    https://docs.dhtmlx.com/gantt/api__gantt_getwbscode.html
gantt.init("gantt_here");
 
gantt.parse({
 "data":[
  {"id":1, "text":"Project #1", "start_date":"28-03-2013", "duration":"11", 
    "parent":"0", "open": true},
  {"id":2, "text":"Task #1", "start_date":"01-04-2013", "duration":"18", "parent":"1"},
  {"id":3, "text":"Task #2", "start_date":"02-04-2013", "duration":"8", "parent":"1"}
 ],
 "links":[]
});
 
var wbs_code = gantt.getWBSCode(gantt.getTask(3)) // -> returns "1.2"
  1. 通过其全局任务索引返回任务
    https://docs.dhtmlx.com/gantt/api__gantt_gettaskbyindex.html
var globalTaskIndex = gantt.getGlobalTaskIndex(19); // -> 10
 
var task = gantt.getTaskByIndex(10); 
// -> {id:"19", text:"Task name", type:"project", order:"10", progress:0.4, …}
  1. 返回指定时间段内发生的任务的集合
    https://docs.dhtmlx.com/gantt/api__gantt_gettaskbytime.html
var tasks = gantt.getTaskByTime(new Date(2013,3,10),new Date(2013,4,10)); 
for (var i=0; i<tasks.length; i++){
       alert(tasks[i].text);
}
// or
var tasks = gantt.getTaskByTime();//returns all tasks
  1. 返回指定父分支的一级子任务
var tasks = {
  data:[
     {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, 
     open:true},
     {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8,
     parent:"p_1"},
     {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8,
     parent:"p_1"}
   ]
};
gantt.init("gantt_here");
gantt.parse(tasks);
 
gantt.getChildren("p_1");//->["t_1", "t_2"]
  1. 检查当前是否选择了指定的任务
    https://docs.dhtmlx.com/gantt/api__gantt_isselectedtask.html
gantt.templates.task_class = 
gantt.templates.grid_row_class = 
gantt.templates.task_row_class = function (start, end, task) {
    if (gantt.isSelectedTask(task.id))
        return "gantt_selected";
};
  1. 检查指定的任务是否存在
    https://docs.dhtmlx.com/gantt/api__gantt_istaskexists.html
    添加新任务
    https://docs.dhtmlx.com/gantt/api__gantt_addtask.html
gantt.addTask({
    id:10,
    text:"Task #5",
    start_date:"02-09-2013",
    duration:28
}, "project_2");
 
gantt.isTaskExists(10); // ->true
  1. 检查指定任务当前是否在甘特图中呈现
    https://docs.dhtmlx.com/gantt/api__gantt_istaskvisible.html
var tasks = {
  data:[
     {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, 
     open:true},
     {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8,
     parent:"p_1"},
     {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8,
     parent:"p_1"}
   ]
};
gantt.init("gantt_here");
gantt.parse(tasks);
 
gantt.isTaskVisible("t_1"); // ->true
  1. 返回时间刻度的配置
    https://docs.dhtmlx.com/gantt/api__gantt_getscale.html
gantt.getScale();
  1. 获取甘特图中当前加载的任务数
    https://docs.dhtmlx.com/gantt/api__gantt_gettaskcount.html
gantt.getTaskCount();
  1. 获取分支中任务的索引
    https://docs.dhtmlx.com/gantt/api__gantt_gettaskindex.html
var tasks = {
  data:[
     {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, 
        open:true},
     {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8,
        parent:"p_1"},
     {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8,
        parent:"p_1"}
   ]
};
gantt.init("gantt_here");
gantt.parse(tasks);
 
var taskIndex = gantt.getTaskIndex("t_1"); // -> 0
var globalTaskIndex = gantt.getGlobalTaskIndex("t_1"); // -> 1
  1. 返回任务的类型
    https://docs.dhtmlx.com/gantt/api__gantt_gettasktype.html
var type = gantt.getTaskType(gantt.getTask(12));
  1. 返回数据存储的配置对象
    https://docs.dhtmlx.com/gantt/api__gantt_getdatastore.html
var tasksStore = gantt.getDatastore("task");
//获取所有的ID
gantt.getDatastore("task").fullOrder
//获取所有节点
gantt.getDatastore("task").pull
  1. 返回当前选定任务的数组
    https://docs.dhtmlx.com/gantt/api__gantt_getselectedtasks.html
gantt.getSelectedTasks();
// 这个方法是在multiselect扩展中定义的,所以需要激活multiselect插件。
gantt.plugins({
    multiselect: true
});
gantt.config.multiselect = true; // 多选
  1. 返回所选任务的 id
    https://docs.dhtmlx.com/gantt/api__gantt_getselectedid.html
var tasks = {
  data:[
     {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, open:true},
     {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8, parent:"p_1"},
     {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8, parent:"p_1"}
   ]
};
 
gantt.init("gantt_here");
gantt.parse(tasks);
 
gantt.selectTask("t_1"); 
gantt.getSelectedId(); // -> "t_1"
  1. 选择指定的任务
    https://docs.dhtmlx.com/gantt/api__gantt_selecttask.html
var tasks = {
  data:[
     {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, open:true},
     {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8, parent:"p_1"},
     {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8, parent:"p_1"}
   ]
};
 
gantt.init("gantt_here");
gantt.parse(tasks);
 
gantt.selectTask("t_1");

// 该方法调用onTaskSelected事件。
gantt.attachEvent("onTaskSelected", function(id){
    //any custom logic here
});
  1. 检查指定项目是否有子任务
    https://docs.dhtmlx.com/gantt/api__gantt_haschild.html
var tasks = {
  data:[
     {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, 
     open:true},
     {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8,
     parent:"p_1"},
     {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8,
     parent:"p_1"}
   ]
};
gantt.init("gantt_here");
gantt.parse(tasks);
 
gantt.hasChild("p_1"); //-> true gantt.hasChild("t_1"); //-> false
  1. 获取屏幕上可见的任务数(未折叠的任务)
    https://docs.dhtmlx.com/gantt/api__gantt_getvisibletaskcount.html
gantt.getVisibleTaskCount();
  1. 更新指定的任务
    https://docs.dhtmlx.com/gantt/api__gantt_updatetask.html
var taskId = gantt.addTask({
    id:10,
    text:"Task #10",
    start_date:"02-04-2013",
    duration:8,
    parent:1
});
 
gantt.getTask(taskId).text = "Task #13"; //changes task's data
gantt.updateTask(taskId); //renders the updated task

gantt.attachEvent("onAfterTaskUpdate", function(id,item){
    //any custom logic here
});
  1. 打开具有指定 id 的分支
    https://docs.dhtmlx.com/gantt/api__gantt_open.html
var tasks = {
  data:[
     {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18},
     {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8,
     parent:"p_1"},
     {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8,
     parent:"p_1"}
   ]
};
 
gantt.init("gantt_here");
gantt.parse(tasks);
gantt.open("p_1");

gantt.attachEvent("onTaskOpened", function(id) {
    //any custom logic here
});
  1. 关闭具有指定 id 的分支
    https://docs.dhtmlx.com/gantt/api__gantt_close.html
var tasks = {
  data:[
     {id:"p_1", text:"Project #1", start_date:"01-04-2013", duration:18, 
     open:true},
     {id:"t_1", text:"Task #1", start_date:"02-04-2013", duration:8,
     parent:"p_1"},
     {id:"t_2", text:"Task #2", start_date:"11-04-2013", duration:8,
     parent:"p_1"}
   ]
};
gantt.init("gantt_here");
gantt.parse(tasks);
 
gantt.close("p_1");

gantt.attachEvent("onTaskClosed", function(id) {
    alert("You've closed a branch with id="+id);
});
  1. 删除指定的任务
    https://docs.dhtmlx.com/gantt/api__gantt_deletetask.html
gantt.addTask({
    id:10,
    text:"Project #1",
    start_date:"02-09-2013",
    duration:28
});
 
gantt.deleteTask(10);
gantt.attachEvent("onBeforeTaskDelete", function(id,item){
    //any custom logic here
    return true;
});
gantt.attachEvent("onAfterTaskDelete", function(id,item){
    //any custom logic here
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值