获取任务节点 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(无论嵌套级别如何:相同或不同) https://docs.dhtmlx.com/gantt/api__gantt_getnext.html
在这里插入代码片
返回下一项的 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" ) ;
gantt. getParent ( "p_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 ) ;
返回表格中任务行的 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 ) ;
按指定条件查找任务 https://docs.dhtmlx.com/gantt/api__gantt_gettaskby.html
var userTasks = gantt. getTaskBy ( "user_id" , 5 ) ;
var userTasks = gantt. getTaskBy ( function ( task ) {
return task. user_id == 5 || ! task. user_id;
} ) ;
var userTasks = gantt. getTaskBy ( task => task. user_id == 5 ) ;
通过 WBS 代码返回任务 https://docs.dhtmlx.com/gantt/api__gantt_gettaskbywbscode.html
var task = gantt. getTaskByWBSCode ( "1.2" ) ;
返回任务的 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 ) )
通过其全局任务索引返回任务 https://docs.dhtmlx.com/gantt/api__gantt_gettaskbyindex.html
var globalTaskIndex = gantt. getGlobalTaskIndex ( 19 ) ;
var task = gantt. getTaskByIndex ( 10 ) ;
返回指定时间段内发生的任务的集合 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) ;
}
var tasks = gantt. getTaskByTime ( ) ;
返回指定父分支的一级子任务
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" ) ;
检查当前是否选择了指定的任务 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" ;
} ;
检查指定的任务是否存在 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 ) ;
检查指定任务当前是否在甘特图中呈现 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" ) ;
返回时间刻度的配置 https://docs.dhtmlx.com/gantt/api__gantt_getscale.html
gantt. getScale ( ) ;
获取甘特图中当前加载的任务数 https://docs.dhtmlx.com/gantt/api__gantt_gettaskcount.html
gantt. getTaskCount ( ) ;
获取分支中任务的索引 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" ) ;
var globalTaskIndex = gantt. getGlobalTaskIndex ( "t_1" ) ;
返回任务的类型 https://docs.dhtmlx.com/gantt/api__gantt_gettasktype.html
var type = gantt. getTaskType ( gantt. getTask ( 12 ) ) ;
返回数据存储的配置对象 https://docs.dhtmlx.com/gantt/api__gantt_getdatastore.html
var tasksStore = gantt. getDatastore ( "task" ) ;
gantt. getDatastore ( "task" ) . fullOrder
gantt. getDatastore ( "task" ) . pull
返回当前选定任务的数组 https://docs.dhtmlx.com/gantt/api__gantt_getselectedtasks.html
gantt. getSelectedTasks ( ) ;
gantt. plugins ( {
multiselect : true
} ) ;
gantt. config. multiselect = true ;
返回所选任务的 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 ( ) ;
选择指定的任务 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" ) ;
gantt. attachEvent ( "onTaskSelected" , function ( id ) {
} ) ;
检查指定项目是否有子任务 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" ) ;
获取屏幕上可见的任务数(未折叠的任务) https://docs.dhtmlx.com/gantt/api__gantt_getvisibletaskcount.html
gantt. getVisibleTaskCount ( ) ;
更新指定的任务 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" ;
gantt. updateTask ( taskId) ;
gantt. attachEvent ( "onAfterTaskUpdate" , function ( id, item ) {
} ) ;
打开具有指定 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 ) {
} ) ;
关闭具有指定 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) ;
} ) ;
删除指定的任务 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 ) {
return true ;
} ) ;
gantt. attachEvent ( "onAfterTaskDelete" , function ( id, item ) {
} ) ;