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.ActionEventArgsargs)
{
if (args.ActionType == ActionType.EventCreate)
{
MyClass record = args.AddedRecords[0];
Services.InsertRecord(record);
}
}
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);
Thanks a lot for your great suggestion. Problem solved.
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
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});
}
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
|
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;
}
|
|
<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>
|
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.