Set non-zero offset for a dependency to avoid moving tasks?

Hi,

Currently when say a FS dependency is added, the second task gets moved so that it start day matches that of the first task's end date. This is because the dependency laf is 0 by default, as far as I understand. We would like to avoid moving tasks when adding dependencies. Is it possible to set the initial offset so that the tasks would retail their position?

Thanks. 

6 Replies

PP Pooja Priya Krishna Moorthy Syncfusion Team May 27, 2020 05:54 AM UTC

Hi Dmitry, 
Yes, it is possible to prevent validation of start date and end date of taskbar while adding dependency. This can be done by disabling the property enablePredecessorValidation. Please find the below code example. 


<GanttComponent id='Editing'   
  //... 
  enablePredecessorValidation ={false}>          
</GanttComponent> 

Please find the below sample link. 

Regards, 
Pooja K. 



DV Dmitry Vorobyev May 27, 2020 06:22 AM UTC

Thank you so much! We are really excited about your components!

BTW, what is the correct way of purchasing and applying a license (if any)?

Thanks!


DV Dmitry Vorobyev May 27, 2020 06:55 AM UTC

Sorry - yet another dependencies related question.

Is it possible to limit task connections to only subtasks belonging to the same parent (job)? I can validate the connection in the event handler, but on the Dependency task there is a list of all tasks anyway. Can we limit possible tasks to connect to to be the siblings of the current tasks only?

Thanks in advance!


LG Logeswari Gopalakrishnan Syncfusion Team May 28, 2020 02:00 PM UTC

Hi Dmitry, 
 
We have analyzed your query and achieved your requirement to prevent dependency connection of same parent task on editing actions using actionBegin and actionComplete event . Please find the below code snippet. 
 
<GanttComponent id='Editing' ref={gantt =>this.ganttInstance = gantt}  
actionBegin={this.actionBeginEvent.bind(this)} actionComplete={this.actionCompleteEvent.bind(this)}> 
 <Inject services={[Edit, Selection, Toolbar, DayMarkers]} /> 
</GanttComponent> 
…/// 
 
this.actionBeginEvent = function(args) { 
         if (args.columnName === "Predecessor" && args.type === "save") { 
           var from = + args.value[0]; 
           var to = args.rowData.TaskID; 
           var fromRecord = this.ganttInstance.getRecordByID(from); 
           if (fromRecord.parentItem.taskId === args.rowData.parentItem.taskId) { 
             args.cancel = true; 
           } 
           this.ganttInstance.treeGrid.endEdit(); 
         } 
        else if (args.requestType === "ValidateDependency") { 
           var fromTask = this.ganttInstance.getRecordByID(args.fromItem.taskId); 
           var toTask = this.ganttInstance.getRecordByID(args.toItem.taskId); 
           if (fromTask.parentItem.taskId === toTask.parentItem.taskId) { 
             args.isValidLink = false; 
           } 
         } 
        }; 
this.actionCompleteEvent = function (args) { 
          if ((args.action == "DialogEditing" && args.requestType == "save")) { 
            var from= + args.data.Predecessor[0]; 
           var to = args.data.TaskID; 
           var fromRecord = this.ganttInstance.getRecordByID(from); 
           if (fromRecord.parentItem.taskId === args.data.parentItem.taskId) { 
            this.ganttInstance.removePredecessor(args.data.TaskID); 
           } 
          } 
        } 
 
 
 
Please find the below sample link. 
 
 
Please let us know if you need further details on this. 
 
Regards, 
Logeswari G 



DV Dmitry Vorobyev May 28, 2020 03:46 PM UTC

Sorry but your code doesn't work.

1. If you want to allow to connect only tasks belonging to the same parent, you should replace the === operator with !== everywhere.

2. Your code fails with error when adding dependencies to a newly created task.

3. Your code doesn't limit the tasks on the Dependency tab to current task's siblings. Instead, it cancels an invalid dependency on save. This is a quite misleading UX. Can we filter the tasks listed on the Dependency tab?

4. Are you sure that task id is always 1-digit?

var from = +e.data.Predecessor[0];


LG Logeswari Gopalakrishnan Syncfusion Team May 30, 2020 08:29 AM UTC

Hi Dmitry, 
  
Please find the below response.  
  
S.No  
Queries  
Syncfusion Comments  
  
1.  
  
If you want to allow to connect only tasks belonging to the same parent, you should replace the === operator with !== everywhere. 
Sorry for the inconvenience caused. We misunderstand the query. That’s why we achieved to allow to connect tasks not belonging to the same parent. 
2.  
Your code fails with error when adding dependencies to a newly created task. 
  
  
We can limit the dependency collections in dialog (both add and edit )using actionComplete event. Please find the below code snippet. 
  
  
this.actionCompleteEvent = function (args) { 
…//// 
else if (args.requestType === "openEditDialog" || args.requestType === "openAddDialog") { 
            var selectedRecord; 
            var childRecords; 
            if (args.requestType === "openAddDialog") { 
              selectedRecord = this.ganttInstance.getRecordByID(this.ganttInstance.selectedRowIndex + 1); 
              childRecords = selectedRecord.childRecords; 
            } else { 
              selectedRecord = args.data; 
              var selectedRecordParent = this.ganttInstance.getRecordByID(selectedRecord.parentItem.taskId); 
              childRecords = selectedRecordParent.childRecords; 
            } 
            for (var i = 0; i< childRecords.length; i++) { 
              ids.push(childRecords[i].TaskID); 
            } 
              var tabObj = document.getElementById("Editing_Tab").ej2_instances[0]; 
              tabObj.selected = function(args) { 
                if (args.selectedIndex === 1) { 
                  var grid = document.getElementById("EditingDependencyTabContainer").ej2_instances[0]; 
                  grid.actionComplete = function (args) { 
                    var dropDown = document.getElementById("EditingDependencyTabContainername").ej2_instances[0]; 
                    dropDown.actionBegin = function (args) { 
                      var dataCollection = args.data.dataSource.json; 
                      var newData = []; 
                      for (var l =0; l< ids.length; l++) { 
                        for (var i =0; i< dataCollection.length; i++) { 
                        if (ids[l].toString()===dataCollection[i].id ) { 
                          newData.push(dataCollection[i]); 
                        } 
                      } 
                      } 
                      ids = []; 
                      args.data.dataSource.json = newData; 
                    } 
  
                  } 
          } 
        }; 
      } 
        }; 
  
Note: In this sample we added newly record as Child. 
  
3. 
Your code doesn't limit the tasks on the Dependency tab to current task's siblings. Instead, it cancels an invalid dependency on save. This is a quite misleading UX. Can we filter the tasks listed on the Dependency tab? 
4. 
Are you sure that task id is always 1-digit? 
To handle 2 digit value and more than one predecessor value , we can use split and match operator. Please find the below code snippet. 
  
if (args.action == "CellEditing" && args.requestType == "save") { 
            var predecessorCollection = args.data.Predecessor.split(','); 
            var predecessorLength = predecessorCollection.length; 
            var from,fromRecord; 
            var resultPredecessor= ""; 
            for (var i = 0; i< predecessorLength; i++) { 
              from = parseInt(predecessorCollection[i].match(/\d+/),10); 
              fromRecord = this.ganttInstance.getRecordByID(from); 
              if (fromRecord.parentItem.taskId === args.data.parentItem.taskId) { 
                resultPredecessor = resultPredecessor + predecessorCollection[i] + ','; 
              } 
            } 
            this.ganttInstance.updatePredecessor(args.data.TaskID, resultPredecessor.substr(0, resultPredecessor.length - 1)); 
          } 
  
  
  
  
We have prepared sample for this. Please find the below sample link. 
  
  
Please let us know if you need further details on this. 
  
Regards, 
Logeswari G

Loader.
Up arrow icon