Monish
Monish

Reputation: 11

ngx-bootstrap Daterangepicker open with current and previous month

By default ngx-bootstrap Date range picker shows current and Next month.

I want to set to Current month and previous Month, If the current month is December it should open with November and December.

There is no option found in bsConfig

Upvotes: 0

Views: 2261

Answers (2)

sam
sam

Reputation: 57

this feature was now added use the following property in the config:

[bsConfig]="{ showPreviousMonth: true }"

https://valor-software.com/ngx-bootstrap/#/components/datepicker#daterangepicker-previous-month

Upvotes: 1

Asaf Hananel
Asaf Hananel

Reputation: 7302

You can do a workaround to solve it:

in html:

 <input
      formControlName="dateRange"
      type="text"
      bsDaterangepicker
      #rangePicker="bsDaterangepicker"
      (onShown)="onDateRangePickerShow()"/>
  </div>

in component:

export class Component {

@ViewChild('rangePicker') rangePicker;

onDateRangePickerShow() {
  // This is a workaround to show previous month
  const prevMonth = new Date(moment().subtract(1, 'month'));
  this.rangePicker._datepicker.instance.monthSelectHandler({ date: prevMonth });
}
}

Upvotes: 1

Related Questions