|
[app.component.html]
<ejs-gantt id="ganttDefault"
.. ////
(actionComplete)="onActionComplete($event)" (actionBegin)="onActionBegin($event)">
</ejs-gantt>
[app.component.ts]
export class AppComponent {
..////
public ngOnInit(): void {
this.data = editingData;
../////
}
public onActionComplete(args: any): void {
if (args.action == "add" && args.requestType == "add") {
console.log("Triggerd action complete event");
}
}
public onActionBegin(args: any): void {
if (args.action == "beforeAdd" && args.requestType == "beforeAdd") {
console.log("Triggerd action begin event");
}
}
} |
|
[app.component.html]
//Render gantt
<ejs-gantt id="contextMenu" #gantt
…//
(toolbarClick)="toolbarClick($event)">
</ejs-gantt>
// Render Dialog
<ejs-dialog id="editdialog" #editdialog width="700px" isModal='true' header='Add Custom Dialog' [buttons]='buttons' [visible]='visible'[animationSettings]='animationSettings'>
<ng-template #content>
<ejs-textbox id="taskname" #taskname placeholder="Task Name" width="300px"></ejs-textbox>
</ng-template>
</ejs-dialog>
[app.component.ts]
export class AppComponent {
….////
// Trigger when ok button click
public okButton: EmitType<object> = () => {
var tasknameObj = (document.getElementById("taskname") as any).ej2_instances[0];
let record: object = {
TaskName: tasknameObj.value,
};
this.gantt.addRecord(record); // Add record using public method
tasknameObj.value = "";
this.editdialog.hide();
}
public cancelButton: EmitType<object> = () => {
this.editdialog.hide();
}
public visible: Boolean = false;
public animationSettings: Object = { effect: 'None' };
…////
public ngOnInit(): void {
this.data = new DataManager({
url: 'https://localhost:44379/Home/UrlDatasource',
adaptor: new UrlAdaptor,
batchUrl: 'https://localhost:44379/Home/BatchUpdate'
});
…..////
}
public toolbarClick(args: any) {
if (args.item.text == "Add") {
args.cancel = true; // Cancel default add dialog
this.renderDialog(); // Render custom dialog
}
}
public buttons: Object = [
{
'click': this.okButton.bind(this),
buttonModel:{
content: 'OK',
isPrimary: true
}
},
{
'click': this.cancelButton.bind(this),
buttonModel: {
content: 'Cancel'
}
}
]
public renderDialog() {
this.editdialog.show();
}
}
//server side
[HomeController.cs]
public IActionResult UrlDatasource([FromBody]DataManagerRequest dm)
{
if (DataList == null)
{
ProjectData datasource = new ProjectData();
DataList = datasource.GetUrlDataSource();
}
var count = DataList.Count();
return dm.RequiresCounts ? Json(new { result = DataList, count = count }) : Json(DataList);
}
public IActionResult BatchUpdate([FromBody]CRUDModel batchmodel)
{
….////
if (batchmodel.Added != null)
{
for (var i = 0; i < batchmodel.Added.Count(); i++)
{
DataList.Insert(0,batchmodel.Added[i]);
}
}
return Json(new { addedRecords = batchmodel.Added, changedRecords = batchmodel.Changed, deletedRecords = batchmodel.Deleted });
} |