twinssbc / Ionic2-Calendar

A calendar component based on Ionic framework
https://ionic-calendar-demo.stackblitz.io
MIT License
388 stars 199 forks source link

How to push data count on calendar according to date #585

Open pkpathak007 opened 3 years ago

pkpathak007 commented 3 years ago

Hi Everyone, I'm new to Ionic. I used ionic 2-calendar to show datewise data count show on the calendar, but I'm not able to work because I put data count by using eventSource, this does not work. below I show my code.

/=================== HTML Code ==================/

<calendar
        [eventSource]="eventSource"
        [calendarMode]="calendar.mode"
        [showEventDetail] = "false"
        [currentDate]="calendar.currentDate"
        (onTitleChanged)="onViewTitleChanged($event)"
        (onTimeSelected)="onTimeSelected($event)"
        [dateFormatter]="calendar.dateFormatter"
        step="30"
        [monthviewDisplayEventTemplate]="template"
        >
      </calendar>

/=================== TS File Code ==================/

getDateCaseCount:any;
  getAllDatecase(){
    this.cal_date = new Date().toDateString()
    //alert(this.cal_date);
    this.CommonProcess.getDateCaseCountProcess(this.user_id).subscribe((result:any) => {
      console.log(result.data[0].data[0].next_date);
      if (result.data[0].status == "true"){
        for(let x=0;x<result.data[0].data.length;x++){
          this.eventCopy = {
            startTime:  new Date(),
            endTime: new Date(),
            allDay: true,
          }
         this.eventSource.push(this.eventCopy);
         this.myCal.loadEvents();
        }
        console.log(this.eventCopy);
      }
    });
  }

/======================== Output Wants ===================/ WhatsApp Image 2021-01-13 at 4 16 48 PM

Please Help

twinssbc commented 3 years ago

@pkpathak007 It seems you set the startTime and endTime to the same value. If you set allDay to true, the endTime needs to be at least one day after startTime. You could check README for the event source format. Also you don't need to call loadEvents each time you push an element in the for loop. You could move it out of for loop. Once you fill the eventSource in the for loop, then call loadEvents method.