How to enforce self-referential on an empty gantt when new rows are created

It turns out that if I create a new `GanttComponent` with the data source being an empty array, when new rows are added, subtasks are being created using subobjects/hierarchical reference and not self-referencing. Is there anyway to predefine in advance that the Gantt should record data in self-referencing manner?


2 Replies

GM Gil Michael Regalado July 25, 2021 06:20 AM UTC

Ok it seems one can use the following pattern to achieve this. CodeSanbox

return (
<GanttComponent
id="gantt"
ref={ganttRef}
dataSource={SelfReferenceData}
taskFields={taskFields}
allowReordering={true}
allowRowDragAndDrop={true}
taskMode="Auto"
taskType="FixedWork"
workUnit="Hour"
allowSelection={true}
allowResizing={true}
allowUnscheduledTasks={true}
// enableContextMenu={true}
highlightWeekends={true}
editSettings={ganttSettings}
toolbar={ganttToolbarInitial}
renderBaseline={true}
baselineColor="red"
projectStartDate={projectStartDate}
projectEndDate={projectEndDate}
showOverAllocation={true}
enableMultiTaskbar={true}
showInlineNotes={true}
showColumnMenu={true}
selectionSettings={{ type: "Multiple" }}
height="450px"
actionComplete={(e) => {
if (e?.requestType === "refresh") {
const flatdata = ganttRef.current?.flatData?.map((d) => d.taskData);
console.log(flatdata);
}
}}


MS Monisha Sivanthilingam Syncfusion Team July 26, 2021 09:26 AM UTC

Hi Gil, 
 
Greetings from Syncfusion support. 
 
We are glad you were able to resolve your issue by yourself. 
 
In general, by mapping the parentID field in the taskfields property, the Gantt will be rendered in  Self-referential mode. This field contains values that indicate parent tasks. The following code snippets demonstrate the solution. 
 
Index.js 
 
this.taskFields = { 
  id: 'taskId', 
  name: 'taskName', 
  startDate: 'startDate', 
  endDate: 'endDate', 
  duration: 'duration', 
 progress: 'progress', 
  parentID: 'parentID' 
}; 
 
 
To learn more about data binding in Gantt Chart, please refer our Online Documentation. 
 
Please contact us if you require any further assistance. 
 
Regards, 
Monisha. 


Loader.
Up arrow icon