We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Add days to Gantt

Hi, I was wondering if is possible to pass a number of days to a instance of gantt chart and the chart recalculate the dates.  I don't want to loop through each task. 

Eg:

Initial DataSource:

var GanttData = [
{ TaskID: 1, TaskName: 'Task 1', StartDate: new Date('01/01/2022'), EndDate: new Date('01/02/2022'), },
{ TaskID: 2, TaskName: 'Task 2', StartDate: new Date('01/03/2022'), EndDate: new Date('01/04/2022'), },
{ TaskID: 3, TaskName: 'Task 3', StartDate: new Date('01/05/2022'), EndDate: new Date('01/06/2022'), },
{ TaskID: 4, TaskName: 'Task 4', StartDate: new Date('01/07/2022'), EndDate: new Date('01/08/2022'), },
];


Call a js function to add 1 day to each date

var GanttData = [
{ TaskID: 1, TaskName: 'Task 1', StartDate: new Date('01/02/2022'), EndDate: new Date('01/03/2022'), },
{ TaskID: 2, TaskName: 'Task 2', StartDate: new Date('01/04/2022'), EndDate: new Date('01/05/2022'), },
{ TaskID: 3, TaskName: 'Task 3', StartDate: new Date('01/06/2022'), EndDate: new Date('01/07/2022'), },
{ TaskID: 4, TaskName: 'Task 4', StartDate: new Date('01/08/2022'), EndDate: new Date('01/09/2022'), },
];


How to achieve this?


4 Replies

GM Gopinath Munusamy Syncfusion Team October 24, 2022 08:08 AM

Hi Washington Morais,


We are currently working on your query and we will provide you an update within two business days on October 27, 2022. Until then we appreciate your patience.


Regards,

Gopinath M



GM Gopinath Munusamy Syncfusion Team October 27, 2022 07:17 AM

Hi Washington Morais,


We have checked your query and we have prepared a sample to achieve your requirement. In this sample, we have add one day to each start and end date using a button click, inside the button click event initially we have cloned the data source to an another data object and then add one day to each start and end date of the task. Now we have fetched the data object to the data source, as a result the onPropertyChange method gets hit and the date values gets directly updated into the data Source. We have attached the sample and code snippets for your reference. Please check the below sample and code snippets for more details,


Code Snippets:

[index.js]

document.getElementById('dataSource').addEventListener('click', function () {

  var data = Object.assign([{}], ganttChart.dataSource);

  for (i = 0; i < data.length; i++) {

    var sDate = new Date(ganttChart.dataSource[i].StartDate);

    sDate = new Date(sDate.setDate(sDate.getDate() + 1));

    data[i].StartDate = sDate;

    var eDate = new Date(ganttChart.dataSource[i].EndDate);

    eDate = new Date(eDate.setDate(eDate.getDate() + 1));

    data[i].EndDate = eDate;

  }

  ganttChart.dataSource = data;

});


Sample: https://stackblitz.com/edit/arpt7e-smjysn?file=index.js,index.html


Regards,

Gopinath M



WM Washington Morais October 27, 2022 02:28 PM

Works like a charm!

Thank you!



GM Gopinath Munusamy Syncfusion Team October 28, 2022 01:51 AM

Hi Washington Morais,


You’re most welcome. Please get back to us if you require any further assistance.


Regards,

Gopinath M


Loader.
Live Chat Icon For mobile
Up arrow icon