Our state of the art Gantt chart


Post by Maciej Grzywacki »

I want to add ability to delete dependency in task context menu.

I've achived that by following code, but it's buggy. It deletes dependency, but dragging task makes it visible again.
Consecutive dragging of task leaves dependency not connected to anything.

Is it a bug in Gantt or am I doing something wrong?

Source code of function creating menu position:
function prepareGanttTaskContextMenu({taskRecord, items}) {
  let taskId = taskRecord.id;
  let dependencyStore = taskRecord.getDependencyStore();
  let deleteDependenciesList = [];

  dependencyStore.forEach((dep) => {
    let task = taskId === dep.from ? dep.toTask : (taskId === dep.to ? dep.fromTask : null);
    let direction = taskId === dep.from ? 'To: ' : 'From: ';
    if(task) {
      deleteDependenciesList.push({
        depId: dep.id,
        text   : direction+task.data.name,
        weight : 200,
        onItem() {
          dep.remove();
        }
      });
    }
  });
  if(deleteDependenciesList.length > 0) {
    items.deleteDependency = {
      icon   : 'b-fa b-fa-compress',
      text   : 'Delete dependency',
      cls    : 'b-separator',
      weight : 200,
      menu: {
        items: deleteDependenciesList
      }
    };
  }
}
Function is invoked when gantt is configured.
let ganttConfig = {
    ...,
    features : {
        ...,
        taskContextMenu : {
            processItems({ taskRecord, items }) {
                prepareGanttTaskContextMenu({taskRecord, items});
            }
    },
};
const gantt = new Gantt(ganttConfig);
I attach modified php example from Bryntum Gantt examples
Attachments
php.zip
Modified PHP example.
(684.66 KiB) Downloaded 107 times

Post by sergey.maltsev »

Hi!

Try this code to delete dependency and apply changes to project.
onItem() {
  gantt.dependencyStore.remove(dep);
  gantt.project.propagate();
}

Post by Maciej Grzywacki »

It does exactly what I wanted to.
Thanks.

Post Reply