How to customize the ngx-bootstrap datepicker
You could create a custom component based on the original datepicker adding custom element to template making it look like an integrated element with some css :
First change the height of the datepicker popup :
::ng-deep.bs-datepicker {
height: 350px;
}
Then add the custom element to the datepicker :
<div class="container">
<input type="text" #dp="bsDatepicker" bsDatepicker [(bsValue)]="myDateValue">
<div class="custom-content" *ngIf="dp.isOpen">
<a (click)="customAction()">{{myDateValue | date:'short'}}</a>
</div>
</div>
With some css :
.custom-content {
position: absolute;
z-index: 1081;
top: 390px;
cursor: pointer;
align-self: center;
}
Here is a running stackblitz demo.
A better solution would be to have the possibility to pass a template to the datepicker, but ngx-bootstrap doesn't seem to support that.
sandip
I am software developer. You can reach me on email: [email protected] Love to learn new things always and forever :)
Updated on May 27, 2020Comments
-
sandip almost 4 years
I want to customize the ngx-bootstrap datepicker popup. Basically I want to add link/button in the calendar showing date and on click of that date will get added to date picker field.
I couldn't find any way to customize the datepicker. I am using Angular 5 and ngx-bootstrap: https://valor-software.com/ngx-bootstrap/#/datepicker
Thanks in advance.
-
Winnemucca about 5 years@ibenjelloun why import both
BsDatepickerModule.forRoot(), DatepickerModule.forRoot()
? -
ibenjelloun about 5 years@Winnemucca I removed the DatepickerModule import from the stackblitz.
-
netalex about 5 yearsdon't change something in node_modules ever: you need to overwrite it in a stylesheet with an higher priority.
-
eddy almost 4 yearsHi, do you know I can't reduce the width of the body? No matter what I try I can't make the calendar smaller stackblitz.com/edit/angular-7rxmuq-8qgxp1