添加一个新的依赖链接 https://docs.dhtmlx.com/gantt/api__gantt_addlink.html
var linkId = gantt. addLink ( {
id : 1 ,
source : 1 ,
target : 2 ,
type : gantt. config. links. finish_to_start
} ) ;
gantt. attachEvent ( 'onBeforeLinkAdd' , function ( id, link ) {
let sourceTask = gantt. getTask ( link. source) ;
let targetTask = gantt. getTask ( link. target) ;
console. log ( sourceTask, targetTask) ;
console. log ( sourceTask. type === 'task' && targetTask. type === 'task' ) ;
return sourceTask. type === 'task' && targetTask. type === 'task' ;
} ) ;
gantt. attachEvent ( "onAfterLinkAdd" , function ( id, item ) {
} ) ;
删除指定的依赖链接 https://docs.dhtmlx.com/gantt/api__gantt_deletelink.html
gantt. addLink ( {
id : 1 ,
source : 1 ,
target : 2 ,
type : 1
} ) ;
gantt. deleteLink ( 1 ) ;
gantt. attachEvent ( "onBeforeLinkDelete" , function ( id, item ) {
return true ;
} ) ;
gantt. attachEvent ( "onAfterLinkDelete" , function ( id, item ) {
} ) ;
指定用户创建新依赖链接时显示的工具提示文本 https://docs.dhtmlx.com/gantt/api__gantt_drag_link_template.html
gantt. templates. drag_link = function ( from, from_start, to, to_start ) {
from = gantt. getTask ( from) ;
let text =
'From:<b> ' +
from. taskSpecification +
'</b> ' +
( from_start ? 'Start' : 'End' ) +
'<br/>' ;
if ( to) {
to = ganttObj. getTask ( to) ;
text +=
'To:<b> ' + to. taskSpecification + '</b> ' + ( to_start ? 'Start' : 'End' ) + '<br/>' ;
}
return text;
} ;
指定链接“删除”确认窗口标题中的文本 https://docs.dhtmlx.com/gantt/api__gantt_link_description_template.html
gantt. templates. link_description = function ( link ) {
const from = gantt. getTask ( link. source) ,
to = gantt. getTask ( link. target) ,
types = gantt. config. links;
const from_start = link. type == types. start_to_start;
const to_start = link. type == types. finish_to_start || link. type == types. start_to_start;
let text =
'From <b>' +
from. taskSpecification +
'</b> ' +
( from_start ? 'Start' : 'End' ) +
'<br/>' ;
text +=
'To <b>' + to. taskSpecification + '</b> ' + ( to_start ? 'Start' : 'End' ) + '<br/>' ;
return text;
} ;