14、Gantt Link

  1. 添加一个新的依赖链接
    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){
    //any custom logic here
});

在这里插入图片描述

  1. 删除指定的依赖链接
    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){
    //any custom logic here
    return true;
});
gantt.attachEvent("onAfterLinkDelete", function(id,item){
    //any custom logic here
});
  1. 指定用户创建新依赖链接时显示的工具提示文本
    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;
};

在这里插入图片描述

  1. 指定链接“删除”确认窗口标题中的文本
    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;
};

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值