Data is not getting populated to Angular scheduler

Hi,

Whenever we try to populate data in scheduler it is throwing error and data is not loading. But i could see the data in console.




Html Code:

class="control-section">
class="col-lg-12 content-wrapper">
class="btn btn-primary" (click)="MapDataToScheduler()">Show Assigned task
/>
/>
class="col-lg-12 content-wrapper">
#scheduleObj width='100%' cssClass='timeline-resource-grouping' height='650px'
[group]="group" [workDays]="workDays" [eventSettings]="eventSettings">
field='MemberId' title='Members' [dataSource]='allMembersData' [allowMultiple]='allowMultiple'
name='Members' textField='MemberName' idField='MemberId' colorField='color'>
option="TimelineDay">
option="TimelineWeek">
option="TimelineWorkWeek">
option="TimelineMonth">
option="Agenda">

Ts Code:

import { Component, OnInit, Inject, ViewEncapsulation,ViewChild } from '@angular/core';

import {

TimelineViewsService, AgendaService, GroupModel, EventSettingsModel,

ResizeService, DragAndDropService, EventRenderedArgs, ScheduleComponent

} from '@syncfusion/ej2-angular-schedule';

import { extend } from '@syncfusion/ej2-base';

import { HttpClient } from '@angular/common/http';


@Component({

selector: 'app-view-calendar',

templateUrl: './view-calendar.component.html',

styleUrls: ['./view-calendar.component.css'],

styles: [`

.timeline-resource-grouping.e-schedule:not(.e-device) .e-agenda-view .e-content-wrap table td:first-child {

width: 90px;

}

.timeline-resource-grouping.e-schedule .e-agenda-view .e-resource-column {

width: 100px;

}

`],

encapsulation: ViewEncapsulation.None,

providers: [TimelineViewsService, AgendaService, ResizeService, DragAndDropService]


})

export class ViewCalendarComponent implements OnInit {

@ViewChild(ScheduleComponent, { static: true }) scheduleObj: ScheduleComponent;


public data: Record[] = [];

public eventSettings: EventSettingsModel = { dataSource: this.data };


public scheduleData: Object[] = [];

public allMembersData: Object[] = [];

private _baseUrl: string;

public trackId : string ;

private index : number = 0;

private colorCodeId : number = 0;

public workDays: number[] = [1, 2, 3, 4, 5];

public color: string[] = ['#df5286', '#7fa900', '#ea7a57', '#5978ee', '#b30086','#00bdae'];


public group: GroupModel = {

resources: ['Members']

};

public allowMultiple = true;

constructor(private http: HttpClient, @Inject('BASE_URL') baseUrl: string) {

this._baseUrl = baseUrl;

}


ngOnInit() {

this.MapDataToScheduler();

}


GetAssignedTaskData() {

this.trackId = "TR100001";

var promise = new Promise((resolve, reject) => {

this.http.get(this._baseUrl + 'api/Task/GetViewCalendarData?trackId=' + this.trackId).subscribe((data: any) => {

console.log(data);

resolve(data);

}, error => reject(error));

});

return promise;

}


MapDataToScheduler() {

this.scheduleData = [];

this.GetAssignedTaskData().then((data: any) => {

data.forEach((element: any) => {

if (this.allMembersData.find(item => item["MemberId"] === parseInt(element.userId.substring(2, 8))) == null) {

this.allMembersData.push({

MemberId: parseInt(element.userId.substring(2, 8)),

MemberName: element.userName,

color: this.getColor()

});

}


this.scheduleData.push({

Id: parseInt(element.assignedTaskId.substring(2, 8)),

Subject: element.taskName,

StartTime: element.startDate,

EndTime: element.endDate,

MemberId: parseInt(element.userId.substring(2, 8)),

});

})

this.data = extend([], null, null, true) as Record[];

this.data = extend([], this.scheduleData, null, true) as Record[];


this.scheduleObj.eventSettings = {

allowAdding: false,

allowEditing: false,

allowDeleting: false,

dataSource: this.data,

fields: {

id: 'MemberId',

subject: {

name: 'Subject'

},

startTime: {

name: 'StartTime'

},

endTime: {

name: 'EndTime'

},

}

};


console.log(this.scheduleObj.eventSettings.dataSource);

console.log(this.allMembersData);

});

}


// Method to get color codes for tasks

getColor()

{

if(this.index > 5)

{

this.colorCodeId = (this.index % 5);

}

else

{

this.colorCodeId = this.index;

}

this.index = this.index + 1;

return this.color[this.colorCodeId];

}

}



3 Replies

RM Ruksar Moosa Sait Syncfusion Team March 29, 2022 01:08 PM UTC

Hi Ranjithaa,


We have prepared a sample to check on your reported issue. But unfortunately, we were unable to reproduce it.

Kindly try the below sample and if the issue persists still share the below details to validate your reported issue and serve you better. 

  • Confirm whether the below sample is properly working at your end?
  • If possible, replicate the issue in the below sample.


Sample: https://stackblitz.com/edit/angular-hgpfzh?file=app.component.ts


We will be happy to assist you!


Regards,

Ruksar Moosa Sait



RA Ranjithaa March 31, 2022 06:40 AM UTC

Hi Ruksar Moosa Sait,


Thanks for you reply.


With the predefined data , i don't have any issues, the issues occurs only when I try to get the data from DB via Web Api and populate in Scheduler component.


Iam not sure but I assume it is happening because the scheduler component is trying to populate the data, before it is received from DB. Is there any way to bind the data after it is populated , how to check that..



RM Ruksar Moosa Sait Syncfusion Team April 1, 2022 11:07 AM UTC

Hi Ranjithaa,


We have prepared a CRUD sample with a separate API call for each CRUD actions, which can be downloaded from the following link and the attached service file.

Sample: https://stackblitz.com/edit/angular-scheduler-crud-with-different-api-calls-1zrk8p?file=package.json

Service:  https://www.syncfusion.com/downloads/support/forum/164514/ze/Service771485313

Kindly try the above solution and let us know if you need further assistance.


Regards,

Ruksar Moosa Sait


Loader.
Up arrow icon