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

How to use javascript to bind data source to Gantt Chart control.

I try to use Gantt Chart. I want to bind data source to gantt chart by click a button at client side. 
How can using java script and ajax to bind gantt chart? 

I could not find any documentation on you web site.

Thank you so much

Tianyu Zhang


3 Replies

JA Jesus Arockia Sankaran S Syncfusion Team June 11, 2019 01:18 PM UTC

Hi Tianyu, 

Thank you for contacting Syncfusion support. 
 
We have analyzed your requirement and prepared the simple Gantt sample, In this sample we have rendered the custom button (UPDATE DATA) and when the user click on the button, we have dynamically update the Gantt with new dataSource by using dataSource property. Please refer the below code snippet 
<button id="updateData">Update Data</button> 
 
var ganttChart = new ej.gantt.Gantt({ 
        dataSource: projectNewData, 
        height: '450px', 
        allowSelection: true, 
              //.. 
   }); 
    document.getElementById('updateData').addEventListener('click', () => { 
        var GanttData = [ 
            { 
                TaskID: 1, 
                TaskName: 'Project Initiation', 
                StartDate: new Date('04/02/2019'), 
                EndDate: new Date('04/21/2019'), 
                subtasks: [ 
                    { TaskID: 2, TaskName: 'Identify Site location', StartDate: new Date('04/02/2019'), Duration: 4, Progress: 50 }, 
                    { TaskID: 3, TaskName: 'Perform Soil test', StartDate: new Date('04/02/2019'), Duration: 4, Progress: 50 }, 
                    { TaskID: 4, TaskName: 'Soil test approval', StartDate: new Date('04/02/2019'), Duration: 4, Progress: 50 } 
                ] 
            } 
        ]; 
        setTimeout(function () { 
            ganttChart.dataSource = GanttData; // Binding new dataSource 
        }, 1000) 
    }); 
 
 
 
Please let us know, if you require further assistance on this 
 
Regards, 
Jesus Arockia Sankaran S 



JP Jetniphan Pukkham July 7, 2021 04:03 AM UTC

I have error :

Cannot read property 'toString' of null

when use "ganttChart.dataSource = GanttData; "



LA Lokesh Arjunan Syncfusion Team July 8, 2021 07:29 AM UTC

Hi Tianyu, 
 
We have analyzed the issue and suspect that it may be caused by an incorrect ‘TaskID’ mapping. Please check whether the ‘TaskID’ mapped properly in taskFields property. 
 
Refer to the below code snippet. 
  
var ganttChart = new ej.gantt.Gantt({  
        dataSource: projectNewData,  
        height: '450px',  
        allowSelection: true,  
        taskFields: { 
            id: 'TaskID', 
            name: 'TaskName', 
            startDate: 'StartDate', 
            endDate: 'EndDate', 
            duration: 'Duration', 
            progress: 'Progress', 
            dependency: 'Predecessor', 
            child: 'subtasks' 
        }, 
              //..  
   });  
document.getElementById('updateData').addEventListener('click', () => {  
        var GanttData = [  
            {  
                TaskID: 1,  
                TaskName: 'Project Initiation',  
                StartDate: new Date('04/02/2019'),  
                EndDate: new Date('04/21/2019'),  
                subtasks: [  
                    { TaskID: 2, TaskName: 'Identify Site location', StartDate: new Date('04/02/2019'), Duration: 4, Progress: 50 },  
                    { TaskID: 3, TaskName: 'Perform Soil test', StartDate: new Date('04/02/2019'), Duration: 4, Progress: 50 },  
                    { TaskID: 4, TaskName: 'Soil test approval', StartDate: new Date('04/02/2019'), Duration: 4, Progress: 50 }  
                ]  
            }  
        ];  
        setTimeout(function () {  
            ganttChart.dataSource = GanttData// Binding new dataSource  
        }, 1000)  
    });  
 
 
 
 
If you are still facing the issue, please share us the code snippet. 
 
Regards, 
Lokesh 


Loader.
Up arrow icon