This is a migrated thread and some comments may be shown as answers.

Today button in Calender

5 Answers 284 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
James Shelton Agar
Top achievements
Rank 2
James Shelton Agar asked on 13 Jan 2010, 12:04 AM
Hi, I am trying to have a "today" button in datepicker (and maybe in radcalnder as well)
how would I archive this (at moment, to go to today, need to select month-today) 

5 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 13 Jan 2010, 07:38 AM
Hello James,

I accomplished the same by placing button in FooterTemplate of Calendar in datepicker, then set the date in the click handler of button.

ASPX:
 
    <telerik:RadDatePicker ID="RadDatePicker10" runat="server" Width="140px"
        <Calendar runat="server"
            <FooterTemplate> 
                <div style="width: 100%; text-align: center; background-color: Gray;"
                    <input id="Button1" type="button" value="Today" onclick="GoToToday()" /> 
                </div> 
            </FooterTemplate> 
        </Calendar> 
    </telerik:RadDatePicker> 

JavaScript:
 
    function GoToToday() { 
        var datepicker = $find("<%=RadDatePicker10.ClientID%>"); 
        var dt = new Date(); 
        datepicker.set_selectedDate(dt); 
    } 

-Shinu.
0
James Shelton Agar
Top achievements
Rank 2
answered on 25 Jan 2010, 12:28 AM
works great! thank you for the tip
0
Michael Veltre
Top achievements
Rank 1
answered on 06 Oct 2014, 08:50 PM
How can I accomplish the same function server side?
0
Eyup
Telerik team
answered on 09 Oct 2014, 10:25 AM
Hi Michael,

You can use the SpecialDays collection to achieve this requirement:
http://demos.telerik.com/aspnet-ajax/calendar/examples/functionality/today/defaultcs.aspx

Hope this helps.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
IT-Fjárvakur
Top achievements
Rank 1
answered on 03 Mar 2017, 11:39 AM
A small update

This solution does not work when RadDatePicker is bound in edittemplates in grid and such. Also, if you have multiple RadDatePickers (like date from and date to) you might end up with a huge switch/case or if/else if/else which is not really scalable.


My solution was to change the onClick function so it takes in a parameter.
This is somewhat of a "hack" but since there is only one popup calendar available when you open up your the datepicker, just select the first one. That leaves you with the RadCalender and you can set the date from there.

Btw - it's 2017. Telerik should add this function to calendar pick both server and client side.

<input id="Button1" type="button" value="Today" onclick="GoToToday(this)" />


function GoToToday(aButtonNode)
        {
            var _calenders = $(".RadCalendarPopupShadows");
            var _today = new Date();
            var todayTriplet = [_today.getFullYear(), _today.getMonth() + 1, _today.getDate()];
            $find(_calenders[0].childNodes[0].id).selectDate(todayTriplet, true);
        }
Tags
Calendar
Asked by
James Shelton Agar
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
James Shelton Agar
Top achievements
Rank 2
Michael Veltre
Top achievements
Rank 1
Eyup
Telerik team
IT-Fjárvakur
Top achievements
Rank 1
Share this question
or