gantt chart CRUD special case

May I ask for a sample code of the gantt chart, with taskbar editing enabled, has tasks inside, and is using .net core mvc 5.0? Because I copied the documentation code and end up creating a project with the error "Uncaught TypeError: n is undefined" in ej2.min.js:10:9672411.

Also, I have a cs file inside Services folder that defines InsertRecord or other CRUD functions, is there anyway to call the service from the ASP.NET Core Gantt Chart, just like this sample code?

    public void ActionCompletedHandler(Syncfusion.Blazor.Schedule.ActionEventArgs args)
{
if (args.ActionType == ActionType.EventCreate)
{
MyClass record = args.AddedRecords[0];
Services.InsertRecord(record);
}
}

14 Replies 1 reply marked as answer

PP Pooja Priya Krishna Moorthy Syncfusion Team December 28, 2021 02:39 PM UTC

Hi desmond , 
  
We have analyzed your query and prepared a sample that performs all the CRUD operations. We suggest you to refer the sample. 
  
  
Please get back to us for further assistance  
  
Regards, 
Premkumar S 



DE desmond December 29, 2021 02:42 PM UTC

I want the CRUD sample to be in .NET 5.0, and I think I must invoke my own service, instead of e-data-manager, because I use a database with login credentials. What I mean by invoke is:

Services.InsertRecord(record);




PP Pooja Priya Krishna Moorthy Syncfusion Team December 29, 2021 03:25 PM UTC

Hi Desmond , 
  
We have analyzed your query and will share further details within one business day on 30th December 2021. We appreciate your patience until then. 
  
Regards, 
Premkumar S 



PP Pooja Priya Krishna Moorthy Syncfusion Team December 30, 2021 02:00 PM UTC

Hi Desmond , 
  
We can map service URL using datamanager it will directly hit the server method for CRUD operation . We suggest you to use RemoteSaveAdaptor in dataManager for your requirement. In RemoteSaveAdaptor CRUD operations can be mapped to the server-side by using batchUrl properties. We have shared our online documentation of   Remote Save Adaptor and Hosted URL  for your reference. 
  
  
  
Please contact us for further assistance. 
  
Regards, 
Premkumar S 


Marked as answer

DE desmond January 1, 2022 08:00 AM UTC

Thanks a lot for your great suggestion. Problem solved.



RP Ranjani Prabakaran Syncfusion Team January 3, 2022 01:06 PM UTC

 Desmond, 
  
Great! Please dont hesitate to contact us if you need any further assistance. 
  
Regards, 
Ranjani 



DE desmond January 11, 2022 12:26 PM UTC

Oops, I accidentally created an error "System.NullReferenceException: Object reference not set to an instance of an object.". Just one request: May I get an example of using RemoteSaveAdaptor for CRUD actions in the Gantt chart? I think I have something wrong with the batchUpdate function



LA Lokesh Arjunan Syncfusion Team January 12, 2022 01:39 PM UTC

Hi Desmond, 
  
We need some time to check your query and will share further details within two business days on 17th January 2022. Until then we appreciate your patience. 
  
Regards, 
Premkumar S 



DE desmond January 12, 2022 04:18 PM UTC

For your reference, this is my code. I get "Object reference not set to an instance of an object" when I do anything. Below is a sample trying to read a task in the controller function:

Besides, here is the JSON I get from the browser debugger when it complains me there is no instance, in other words, referencing null. I get table = null in the JSON:

{"changed":[],

"added":[{"taskid":3,

"taskname":"New Task 3",

"startdate":"2022-01-31T00:00:00.000Z",

"enddate":"2022-01-31T09:00:00.000Z",

"duration":1,

"progress":0,

"work":"0.00 hours",

"predecessor":"",

"parentid":null,

"null":null}],

"action":"batch",

"table":null,

"key":"taskid"}

cshtml:

<div class="row">
<div class="col-md-12">
<ejs-gantt id='Gantt' height="450px" enableMultiTaskbar="true" enableContextMenu="true" allowResizing="true" allowSelection="true" projectStartDate="06/10/2021" projectEndDate="06/10/2022" allowUnscheduledTasks="true" toolbar="@(new List() { "Add","Edit","Update","Delete","Cancel","ExpandAll","CollapseAll","Indent","Outdent"})">
<e-data-manager json="@ViewBag.dataSource"adaptor="RemoteSaveAdaptor" batchUrl="/Gantt/Batch">e-data-manager>
<e-gantt-taskfields id="taskid" parentID="parentid" name="taskname" startDate="startdate" endDate="enddate"duration="duration" progress="progress" dependency="predecessor" work="work" expandState="isexpand">e-gantt-taskfields>
<e-gantt-editsettings allowAdding="true" allowEditing="true" allowDeleting="true" allowTaskbarEditing="true" showDeleteConfirmDialog="true">e-gantt-editsettings>
<e-gantt-editdialogfields>
<e-gantt-editdialogfield type="General">e-gantt-editdialogfield>
<e-gantt-editdialogfield type="Dependency">e-gantt-editdialogfield>
<e-gantt-editdialogfield type="Notes">e-gantt-editdialogfield>
e-gantt-editdialogfields>

ejs-gantt>
div>
div>


Controller:

Controller:"> Copy

public IActionResult Gantt()
{
GanttClass[] DataSource = ....ToArray();
ViewBag.dataSource = DataSource;
return View();
}


public class CRUDModel<T> where T : class
{
public List<T> added { get; set; }
public List<T> changed { get; set; }
public List<T> deleted { get; set; }
publicobject key { get; set; }
publicstring action { get; set; }
public T value { get; set; }
public string table { get; set; }
public IDictionary<string, object> @params { get; set; }
}

public ActionResult Batch([FromBody] CRUDModel<MyClass> batchmodel)
{
foreach(PropertyDescriptor descriptor in TypeDescriptor.GetProperties(batchmodel.added))
{
string name = descriptor.Name;
object value = descriptor.GetValue(batchmodel.added);
Console.WriteLine("{0}={1}", name, value);
}
Console.WriteLine("PRINTFORDEBUG" + batchmodel.value);

return Json(new { addedRecords = batchmodel.added, changedRecords = batchmodel.changed, deletedRecords = batchmodel.deleted, value = batchmodel.value, action = batchmodel.action, key = batchmodel.key});
}


PP Pooja Priya Krishna Moorthy Syncfusion Team January 13, 2022 12:28 PM UTC

Hi Desmond, 
  
Thank you for sharing the code snippets with us. We will validate and share the details on the promised date. Until then we appreciate your patience. 
  
Regards, 
Premkumar S


DE desmond January 16, 2022 04:10 PM UTC

Thanks, I solved the problem already. However, it creates two new problems.


1) I used ViewBag.Resource to get the resource of the Gantt Chart, but how can I update it? I used e-data-manager for the taskbars already, so if I do not think I can use e-data-manager for the resource too.

2) I used DataGrid to manage the resources. I can create, update, delete the resources, but when I do so, it does not update until I build my website the second time. This question is off topic, so I asked it here: https://www.syncfusion.com/forums/172012/datagrid-auto-refresh



MS Monisha Sivanthilingam Syncfusion Team January 19, 2022 04:12 AM UTC

Hi Desmond, 
 
You are welcome. 
 
You can define the resource collection locally in the application itself and then define the resource fields in the Gantt model definition. The below code snippets demonstrate the solution. 
 
HomeController.cs 
 
public IActionResult Index() 
{ 
  ViewBag.projectResources = projectResources(); 
  return View(); 
} 
public static List<ResourceModel> projectResources() 
{ 
  List<ResourceModel> GanttResourcesCollection = new List<ResourceModel>(); 
 
  ResourceModel Record1 = new ResourceModel() 
  { 
    resourceId = "4b65c97f - eae2 - 4ffc - 814f - 02597dfd1fc2", 
    resourceName = "Martin Tamer" 
  }; 
  ResourceModel Record2 = new ResourceModel() 
  { 
    resourceId = "50c2a0df-1efe-41c1-8340-19967f71f3cc", 
    resourceName = "Rose Fuller" 
  }; 
  GanttResourcesCollection.Add(Record1); 
  GanttResourcesCollection.Add(Record2); 
  return GanttResourcesCollection; 
} 
 
 
Index.cshtml 
 
<ejs-gantt id='RemoteData' treeColumnIndex="0" height="450px"  
           toolbar="@(new List<string>() { "Add", "Cancel", "CollapseAll", "Delete", "Edit", "ExpandAll", "Update" })" 
           resources="ViewBag.projectResources"> 
    <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-resourcefields id="resourceId" name="resourceName"></e-gantt-resourcefields> 
</ejs-gantt> 
 
 
Sample:  
 
Regards, 
Monisha. 



DE desmond January 19, 2022 09:16 AM UTC

I think I was not asking clearly about the ViewBag for resource. My viewbag is a list, like your example is. It is taken from the remote database. Once I get the ViewBag the first time from the controller, how can you update it again, and refresh the Gantt Chart? To simplify the scenario, you just think there is a button called refresh, before you click it, you edit the remote database manually. After you click the button, you see the gantt chart has changed records. Again, I do not think I can use e-data-manager again, because it is used for handling the taskbars.



PP Pooja Priya Krishna Moorthy Syncfusion Team January 20, 2022 03:27 PM UTC

Hi desmond, 
  
After you have obtained the resources, we suggest you to use the refresh() method in Gantt to refresh the Gantt chart once again to get the resource details in the grid part and also chart part if you used resources in the chart. 
  
Regards, 
Premkumar 


Loader.
Up arrow icon