0

https://github.com/hsuanxyz/ion2-calendar/issues/241

Here it is written as

you can change the default date color by pushing the days to daysConfig and passing dayConfig: { marked: true} and then you can change the color with .marked class css and also you can pass with the 'cssClass' key

daysConfig.push({
date: new Date(item),
marked: true
});

DayConfig {
date: Date;
marked?: boolean;
disable?: boolean;
title?: string;
subTitle?: string;
cssClass?: string;
}

here's the interface of daysConfig

When i tried like this

 options: CalendarComponentOptions = {
    from: new Date(2000, 0, 1),
    pickMode: 'multi',

    daysConfig: [
      {
        date:new Date(this.absentdate[0]),
        marked:true,
        cssClass: 'my-cal'
      },
      {
        date:new Date(this.absentdate[1]),
        cssClass:'my-cal',
       marked:true
      },
      {
        date:new Date(this.absentdate[2]),
       cssClass:'my-cal',
        marked:true
      }
    ],

  };

it worked

But i have an array of absent_date as

 absentdate :string[]=['2020-01-03', '2020-01-04', '2020-01-28'];

which keeps on varying according to the month.How can i change the hardcoded value to the absent dates that i have given in the array.Please help me.

T Template ::

<ion-calendar [(ngModel)]="date"
                  (change)="onChange($event)"
                  [options]="options"
                  type="string"
                  format="YYYY-MM-DD"
                  readonly="true"

                  >
    </ion-calendar>
13
  • What's your daysConfig length based on? Commented Feb 24, 2020 at 9:10
  • it keeps on varying according to scenarious .different on different months Commented Feb 24, 2020 at 9:19
  • Is it linked to absent[] length and order of date? Commented Feb 24, 2020 at 9:22
  • yes linked to absent[] length Commented Feb 24, 2020 at 9:24
  • You mean daysConfig[] length = absent[] length? Commented Feb 24, 2020 at 9:25

1 Answer 1

1

Initialize the following format for options

options: CalendarComponentOptions = {
    from: new Date(2000, 0, 1),
    pickMode: 'multi',
    daysConfig: []
};

Next, you can loop through the absentdate[] and push each data set into the options as shown below.

absentdate.forEach(element => {
    var data = {
        date:new Date(element), //can give custom data
        marked:true, //can give custom data
        cssClass: 'my-cal' //can give custom data
    }
    options.daysConfig.push(data)
})

Note: This might sort the data sometimes. if you do not want the sort, you can use the below line instead of push. It will insert the data at the end of the array every iteration

options.daysConfig.splice(options.daysConfig.length, 0, data)

This should provide following output. Let me know if this was what you were looking for :)

{ from: 1999-12-31T18:30:00.000Z,
  pickMode: 'multi',
  daysConfig:[ 
      { 
          date: 2020-01-03T00:00:00.000Z,
          marked: true,
          cssClass: 'my-cal' 
      },
      { 
          date: 2020-01-04T00:00:00.000Z,
          marked: true,
          cssClass: 'my-cal' 
      },
      { 
          date: 2020-01-28T00:00:00.000Z,
          marked: true,
          cssClass: 'my-cal' 
      } 
  ] 
}
Sign up to request clarification or add additional context in comments.

1 Comment

thanks Srikar B S this worked fabulously.Thank you so much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.