|
[CSHTML]
@(Html.EJ().Gantt("Gantt").
ClientSideEvents(eve=>{
eve.ActionComplete("ActionComplete");
})
//…
)
<script type="text/javascript">
function ActionComplete(args) {
if (args.requestType == "indent" || args.requestType == "outdent" || args.requestType == "recordUpdate" || (args.requestType === 'save' && args.modifiedRecord) || args.requestType == "drawConnectorLine") {
var ganttRec = [];
// Dialog Editing
if (args.requestType == "save")
data = args.modifiedRecord;
else if (args.requestType == "drawConnectorLine")
data = args.currentRecord;
else
data = args.data; // Cell Editing
if (!ej.isNullOrUndefined(data.ResourceID))
data.ResourceID = UpdateResourceID(data.ResourceID);
ganttRec.push(data);
if (args.updatedRecords && args.updatedRecords.length)
ganttRec = ganttRec.concat(args.updatedRecords);
updateModifiedGanttRecords(ganttRec);
}
//Newly Added Record is obtained here , which can be updated to database
else if (args.requestType == "save" && args.addedRecord) {
var data = args.addedRecord.item;
if (!ej.isNullOrUndefined(data.ResourceID))
data.ResourceID = UpdateResourceID(data.ResourceID);
$.ajax({
type: "POST",
url: '/Gantt/Add',
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data),
dataType: "json",
});
// args.updatedRecords will have the array of dependent hierarchy of modified
//parents record when add new record as child of another record.
if (args.updatedRecords && args.updatedRecords.length)
updateModifiedGanttRecords(args.updatedRecords);
}
//To update the database on delete action
else if (args.requestType == "delete") {
var data = args.data.item;
if (!ej.isNullOrUndefined(data.ResourceID))
data.ResourceID = UpdateResourceID(data.ResourceID);
$.ajax({
type: "POST",
url: '/Gantt/Delete',
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data),
dataType: "json",
});
if (args.data.hasChildRecords) {
deleteChildRecords(args.data);
}
if (args.updatedRecords && args.updatedRecords.length)
updateModifiedGanttRecords(args.updatedRecords);
}
}
function updateModifiedGanttRecords(records) {
var modifiedRecord = [];
if (records && records.length) {
var length = records.length;
for (var i = 0; i < length; i++)
modifiedRecord.push(records[i].item);
}
$.ajax({
type: "POST",
url: '/Gantt/Update',
contentType: "application/json; charset=utf-8",
data: modifiedRecord,
dataType: "json",
});
}
//Delete inner level child records
function deleteChildRecords(record) {
var childRecords = record.childRecords,
length = childRecords.length,
count, currentRecord;
for (count = 0; count < length; count++) {
currentRecord = childRecords[count];
var data = currentRecord.item;
$.ajax({
type: "POST",
url: '/Gantt/Delete',
contentType: "application/json; charset=utf-8",
data: data,
dataType: "json",
});
if (currentRecord.hasChildRecords) {
deleteChildRecords(currentRecord);
}
}
}
</script> |
|
[Controller.cs]
public ActionResult Index()
{
var data = GanttTaskData.GetData();
ViewBag.dataSource = data;
return View();
}
[Index.cshtml]
@(Html.EJ().Gantt("Gantt")
//…….
.Datasource(ViewBag.dataSource)
) |