Hi Herbert,
Yes, we can save the Resource Name and Resource Id to the server using entityframework by passing the resource values to server using Ajax post. Also we can get back the Resource collection using following four properties of Gantt Control.
· ResourceInfoMapping
· ResourceIdMapping
· ResourceNameMapping
· Resources
Code Snippet:
[CSHTML] <script type="text/javascript"> @(Html.EJ().Gantt("Gantt"). //... //To Set the resources ResourceInfoMapping("Resource").// "Resource" which is defined in Gantt data object, i.e Resource column in data table ResourceIdMapping("ResourceID").//"ResourceID" which is defined in Resource datasource var editedRecord = args.data.item; var data = JSON.stringify({ 'Task': editedRecord, 'Resource': args.data.resourceInfo }); $.ajax({ type: "POST", url: "/TreeGrid/Update", //Update is Server side method data: data, traditional:true, contentType: 'application/json' //Resource Definition public class myDropDown { public string ResourceID { get; set; } public string ddtext { get; set; } [HttpPost()] public void Update(TaskData Task, List<myDropDown> Resource) { string IDNumber = Task.TaskId; GanttDataTable data = db.GanttDataTables.First(i => i.TaskId == IDNumber); data.TaskId = Task.TaskId; |
We have prepared a sample based on your requirement, find the sample from below location.
Sample: http://www.syncfusion.com/downloads/support/forum/121446/ze/Mvc5TreeGridSample-174505972
Please let us know, if you need further assistance on this.
Regards,
Dinesh kumar.N
The main thing that I am trying to achieve is add a gantt record with a resource and save it to a table
retrieve that record and also to be able to edit record, I use the gantt table in another part of my program so I need all data.
Thanks for your speedy response
Regards
Edmund Herbert
Query 1 : Add a new Gantt record and be able to add resource to new record (when I do add new record, resource does not show up).
Solution : We request you to set the name of resource id field same for both TaskData and Resources Datasources. Also make sure with the column name of SQL table and Entity Framework Table.
Query 2 : On ActionComplete function I need to send all the data for that gantt record including resource information that was selected so that I can persist to database.
Solution : We can get the complete Gantt Data from parameters (args.data.item) of ActionComplete client side event, in this item collection for resource reference we have passed the Resource ID alone, if we want complete resource details of a particular gantt record then we can get it by args.data.resourceInfo.
Query 3 : I need to be able to edit gantt record and send all the data for that gantt record including resource so that I can persist on database.
Solution : We can update the edited gantt record to database using ActionComplete client side event, when the request type of the event is “recordUpdate”.
Code Snippet :
<script type="text/javascript"> function ActionComplete(args) { if (args.requestType === 'recordUpdate') { var editedRecord = args.data.item; //get all datas of the edited gantt record var data = JSON.stringify({ 'Task': editedRecord, 'Resource': args.data.resourceInfo//get the resource info of the edited gantt record }); $.ajax({ type: "POST", url: "/TreeGrid/Update", //Update is Server side method data: data, traditional:true, contentType: 'application/json' }); } } </script> |
Query 4 : I will not be using parent records I just want to add one task after the other and save to database ( all data fields plus selected resource for that record).
Solution : We can avoid the parent Records by ignoring the “ParentTaskIdMapping” property, and we can add new gantt task with saving all datas of the task to the database using “ActionComplete” client side event, when the request type of the event is “save” also the event parameter should be contain “addedRecord” which is newly added to the control. Also we can get the resource details of the newly added task from “args.addedRecord.resourceInfo”, for more details find the below code snippet,
Code Snippet :
<script type="text/javascript"> function ActionComplete(args) { //args.addedRecord contains all datas of newly added task. if (args.requestType === 'save' && args.addedRecord) { addedItem = args.addedRecord.item; var addedRecord = JSON.stringify({ 'Task': addedItem, //Resource Details of the newly added task. 'Resource': args.addedRecord.resourceInfo }); $.ajax({ type: "POST", url: "/TreeGrid/Add",//Add is Server side method data: addedRecord, traditional: true, contentType: 'application/json' }); } </script> |
We have prepared a sample base on your above requirements, find the sample from below location.
Sample : http://www.syncfusion.com/downloads/support/forum/121446/ze/Mvc5GanttSample198965217
Please let us know, if you need further assistance on this.
Regards,
Dinesh kumar.N
Hi Herbert,
Thanks for your update.
Please let us know, if you need further assistance on this.
Reagrds,
Dinesh kumar.N