loading of data with urladaptor doesn't work

Trying to load data with following code 

View 
                   
                                       gridLines="Both" allowSelection="true" toolbar="@(new List() { "Add", "Edit", "Update", "Delete", "Cancel", "ExpandAll", "CollapseAll", "Indent", "Outdent" })">
                               
                               
                                                    endDate="EndDate" duration="Duration" progress="Progress"
                                                    child="SubTasks" notes="Notes">
                               
                               
                                   
                                   
                                   
                                   
                                   
                                   
                               
                               
                               
                               
                               
                                   
                                   
                                   
                                   
                               
                           
                                        

Controller (Project controller code as per code url above) :

        public async Task GanttData (Guid projectId)
        {
            // Here I make api call and loads the data but for sample purpose I'm loading static data coming from GanttData class file attached herewith
            return Json(new { result = GanttData.ProjectNewData(), count = GanttData.ProjectNewData().Count });
        }

DataObject (GanttData) :
DataStructure file is attached herewith 

When view loads, at that time 'actionfailure' event gets triggered and it provides following error information :

TypeError: Cannot read property 'toString' of null
    at t.createRecord (https://cdn.syncfusion.com/ej2/dist/ej2.min.js:10:8127924)
    at o (https://cdn.syncfusion.com/ej2/dist/ej2.min.js:10:8122982)
    at t.prepareRecordCollection (https://cdn.syncfusion.com/ej2/dist/ej2.min.js:10:8124226)
    at t.prepareDataSource (https://cdn.syncfusion.com/ej2/dist/ej2.min.js:10:8122027)
    at t.cloneDataSource (https://cdn.syncfusion.com/ej2/dist/ej2.min.js:10:8121404)
    at https://cdn.syncfusion.com/ej2/dist/ej2.min.js:10:8119920
    at $ (https://localhost:44309/assets/plugins/global/plugins.bundle.js:64657:7844)
    at U (https://localhost:44309/assets/plugins/global/plugins.bundle.js:64657:7730)
    at MutationObserver.w (https://localhost:44309/assets/plugins/global/plugins.bundle.js:64657:5643)

with this error, empty gantt chart gets loaded. Can you pls provide hint on why above error occurs?

Regards,
Krunal

Attachment: GanttData_f9f7c27.zip

4 Replies 1 reply marked as answer

KR Krunal March 4, 2021 11:17 AM UTC

I tried to edit the view code and it totally messed up the content of the post and save button also got disappeared. I wonder what went wrong. I'm attaching herewith the zip file containing both datasource and view cshtml code. Pls go through the post and provide the fix for this issue with sample project, if possible.

I'm awaiting for this fix eagerly as all work is hold up due to this issue. So hopefully you will revert back soon.

Attachment: GanttData_28660c98.zip


MS Monisha Sivanthilingam Syncfusion Team March 4, 2021 12:24 PM UTC

Hi Krunal, 
 
Thank you for contacting Syncfusion support. 
 
We have analyzed your query and we would like to inform you of a few points. 
 
  1. We think that the reason why you are facing this issue is because, the mapping of the fields do not match in the taskfields mapping and the data source. Please ensure that the mapping of the fields match in the following places.
 
Index.cshtml 
 
<e-gantt-taskfields id="taskId" name="taskName" startDate="startDate" 
                        duration="duration" progress="progress" dependency="predecessor" parentID="parentID"> 
    </e-gantt-taskfields> 
 
 
ProjectData.cs 
 
new GanttDataSource(){ 
                    taskId = 1, 
                    taskName = "Project initiation", 
                    startDate = new DateTime(2019, 03, 29), 
                    endDate = new DateTime(2019, 04, 21), 
                      resources = new List<ResourceModel> 
                { 
                   new ResourceModel { ResourceId = 1, ResourceUnit = 70, ActivityId=40 }, 
                   new ResourceModel { ResourceId = 6 , ActivityId=40} 
                } 
                } 
 
 
 
public class GanttDataSource 
        { 
            public int taskId { get; set; } 
            public string taskName { get; set; } 
            public DateTime? startDate { get; set; } 
            public DateTime? endDate { get; set; } 
            public string duration { get; set; } 
            public int progress { get; set; } 
            public string predecessor { get; set; } 
            public int? parentID { get; set; } 
            public List<ResourceModel> resources { get; set; } 
            public string customColumn { get; set; } 
 
        } 
 
 
  1. Could you please check in the Network tab of your developer console to see if you have mapped the data fields as shown in it ? Please refer the image attached below to see where you have to refer.
 
 
 
  1. We also noticed that you have used child tasks when using remote data. It is best if you used parentId in mapping parent-child relationships in remote data. Please find the documentation link below.
 
 
We have also prepared a sample for your reference. 
 
Regards, 
Monisha. 



KR Krunal March 8, 2021 08:04 AM UTC

Thanks for your answer. 

I managed to bind the data using URLAdaptor now. However, what if some problem occurs with executing the "batchUrl" call on controller side? In this case, UI should not update till the time all the data gets updated on server side. So how in client, I can notify and handle the server side errors? Pls advise. 

Also, I didn't get point no. 3, you have mentioned in your previous reply. Can you pls elaborate on that?

Thanks,
Krunal


MS Monisha Sivanthilingam Syncfusion Team March 9, 2021 11:29 AM UTC

Hi Krunal, 
 
Please find the response for your queries. 
 
SL.No. 
Query 
Syncfusion Comments 
 
However, what if some problem occurs with executing the "batchUrl" call on controller side? In this case, UI should not update till the time all the data gets updated on server side. So how in client, I can notify and handle the server side errors? Pls advise. 
WE can make use of the actionFailure event to reload the old data, if some error occurs while updating the data in the back-end. The following code snippets demonstrate the solution. 

Index.cshtml 
<ejs-gantt id='RemoteData' treeColumnIndex="0" height="450px" actionFailure="actionFailure" toolbar="@(new List<string>() { "Add","Indent","Outdent", "Edit", "Update", "Delete", "Cancel", "ExpandAll", "CollapseAll" })"> 
    <e-data-manager url="/Home/UrlDatasource" adaptor="UrlAdaptor" batchUrl="Home/BatchUpdate"></e-data-manager> 
    <e-gantt-taskfields id="taskId" name="taskName" startDate="startDate" 
                        duration="duration" progress="progress" dependency="predecessor" parentID="parentID"> 
    </e-gantt-taskfields> 
    <e-gantt-editsettings allowAdding="true" allowEditing="true" allowDeleting="true"  
                          allowTaskbarEditing="true" showDeleteConfirmDialog="true"></e-gantt-editsettings> 
</ejs-gantt> 
 
<script> 
    function actionFailure(args) { 
        var ganttObj = document.getElementById("RemoteData").ej2_instances[0]; 
        ganttObj.refresh(); 
    } 
</script> 

We have also prepared a sample for your reference. 
 
Also, I didn't get point no. 3, you have mentioned in your previous reply. Can you pls elaborate on that? 
When rendering the Gantt with SQL database, we suggest using the self-referential data binding to maintain relationships. Because the complex json structure is very difficult to manage it in SQL tables, we need to write a complex queries and we have to write a complex algorithm to find out the proper record details while updating/deleting the inner level task in Gantt data source. We cannot implement both data binding for Gantt control and this is not a recommended way. To know more about this, please refer the Online Documentation link below. 


 
Please contact us if you require any further assistance. 
 
Regards, 
Monisha. 


Marked as answer
Loader.
Up arrow icon