2

I want to create a Kendo DatePicker in Kendo template. Here is my Kendo template.

    <script id="popup-doc-details" type="text/x-kendo-template">
      <input id="DateTesting" style="width: 180px">
    </script>

How can I init Kendo DatePicker. For more info this template is part of a popup and shown when something choose from Kendo DropDown and DatePicker number will be dynamically changed with providing data. DropDown data is like.

    [{name:"test1", tags:[{name:"datename",type:"date"},{name:"datename",type:"date"}]}, {name:"test2", tags:[{name:"datename",type:"date"}]}] 

Example: If I choose test1 from DropDown, Kendo template will load DatePicker according to tags.

I know I can achieve this using loop in Kendo template. but my question is how can I init Kendo DatePicker dynamically.

Greg
  • 9,068
  • 6
  • 49
  • 91
ifaim
  • 350
  • 1
  • 3
  • 9

2 Answers2

2

You can create datepicker in template using MVVM style like this

 <input name="selectedDate" type="date" 
        data-bind="value: selectedDate" 
        data-format="dd MMMM yyyy" 
        data-role="datepicker" />
Dion Dirza
  • 2,575
  • 2
  • 17
  • 21
0

For Angular2/4:

HTML

<!-- Calendar Icon -->
<span #anchor (click)="onToggle()" class="k-icon k-i-calendar"></span>

<!-- Kendo Popup with calendar inside -->
<kendo-popup [anchor]="anchor" (anchorViewportLeave)="show = false" *ngIf="show">
    <kendo-calendar class="pointer" [(value)]="examDate" (valueChange)="calendarFunc($event)"></kendo-calendar>
</kendo-popup>

JS/TS

public onToggle(): void {
    this.show = !this.show;        
}

I use a show variable to display the popup.


For Jquery / Knockout:

Popup Info

Calendar Info

HTML

<!-- Anchor Position with calendar Icon iside --> 
<div class="datepicker-anchor">
    <span class="k-icon k-i-calendar" data-bind="click: onToggle.bind($data)" ></span>
</div>
<!-- Popup with calendar inside -->
<div id="popup">
    <div id="calendar"></div>
</div>                                    

JS/TS

private popup: any;

constructor() {

    function onChangeCalendar() {
        var date = this.value();
        self.onToggle();           
    }

    $("#calendar").kendoCalendar({
        change: onChangeCalendar            
    });

    this.popup = $("#popup").kendoPopup({
        anchor: $(".datepicker-anchor")
    }).data("kendoPopup");
    this.popup.close();
}

onToggle = (): void => {
    this.show = !this.show;

    if(this.show)
        this.popup.open();
    else
        this.popup.close();
};
Demodave
  • 6,242
  • 6
  • 43
  • 58