简体   繁体   中英

Angular jqxSchedular source localData Can't bind from remote

I am trying to use jqxSchedular for my web app.

Schedular couldn't bind from remote data.

Here is my Angular component :

export class CourseScheduleComponent implements OnInit {

  appointmentDataFields: any =
  {
      from: "start",
      to: "end",
      description: "description",
      subject: "subject",
      resourceId: "calendar"
  };

 source = {
    dataType: "array",
    dataFields: [
        { name: 'id', type: 'string' },
        { name: 'description', type: 'string' },
        { name: 'subject', type: 'string' },
        { name: 'calendar', type: 'string' },
        { name: 'start', type: 'date' },
        { name: 'end', type: 'date' }
    ],
    localData: []
}

  resources: any = 
  {
      colorScheme: "scheme04",
      dataField: "calendar",
      source: new jqx.dataAdapter(this.source)
  };

  dataAdapter: any;
  date: any = new jqx.date();

  views: string[] | any[] =
  [
      'dayView',
      'weekView',
      'monthView',
      'agendaView'
  ];

  constructor(private repository: RepositoryService,private router: Router,
    private activeRoute: ActivatedRoute ) { } 

  ngOnInit() {
      this.getCourseSchedules().subscribe(res=>{
      this.source.localData = res as CourseSchedule[];
    },err=>{
      console.log(err);
    });
      this.dataAdapter = new jqx.dataAdapter(this.source)
  }

  getCourseSchedules()
  {
    var courseId : string = this.activeRoute.snapshot.params['id'];
    var apiUrl = `/api/course/schedule?courseId=${courseId}`;
    return this.repository.getData(apiUrl).pipe(
        map(data => {
            let schedules = data as CourseSchedule[];
            let newSchedules:CourseSchedule[] = [];
            schedules.forEach((schedule) => {
                const {start,end,...other} = schedule;
                newSchedules.push(<CourseSchedule>{
                    start: new Date(start),
                    end: new Date(end),
                    ...other
                })
            });
            return newSchedules;
        })
    );

  }

}

When I debug the ngOnInit there is no problem with setting localData. But when I consolled log source,it shows localdata is null.

I couldnt find for remote databinding example for Angular jqxSchedular.

So,basicly it works with local data but at remote it doesnt work.

Please help about this.

You have to add them from the jqx component using addAppointment method as below:

getCourseSchedules()
{
    let self = this;
    var courseId : string = this.activeRoute.snapshot.params['id'];
    var apiUrl = `/api/course/schedule?courseId=${courseId}`;
    return this.repository.getData(apiUrl).pipe(
        map(data => {
            let schedules = data as CourseSchedule[];
            let newSchedules:CourseSchedule[] = [];
            schedules.forEach((schedule) => {
                const {start,end,...other} = schedule;

                var appointment = {
                 start: new Date(start),
                 end: new Date(end),
                 ..other
                };

                self.myScheduler.addAppointment(appointment);

            });
        })
    );
}

Please refer to the API for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM