Send FocusedDate to January 1

4 posts, 0 answers
  1. Jeff
    Jeff avatar
    6 posts
    Member since:
    May 2016

    Posted 31 May Link to this post

    How can I set the FocusedDate to January 1 of the current year?  I have tried a JavaScript function, but the calendar will have the current month as the first month.

    The JavaScript is

    function navigateToJanuary(sender) {
        var todaysDate = new Date();
        var triplet;
        triplet = [todaysDate.getFullYear(), 01, 01];
        sender.navigateToDate(triplet);
     }

    I put an alert box to verify that I am getting the correct date. 2016,1,1

    I have  in the RadCalendar

    <ClientEvents OnLoad="navigateToJanuary" />

    Am I using the wrong client event?

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 01 Jun Link to this post

    Hello Jeff,

    If you would like to have the date as selected you would also need to call the selectDate() method. Check out the following snippets as illustration:

    Markup:

    <telerik:RadCalendar runat="server" ID="RadCalendar1" >
        <ClientEvents OnLoad="clientLoad" />
    </telerik:RadCalendar>

    JavaScript:

    function clientLoad(sender, args) {
        var todaysDate = new Date();
        var calendar = sender;
     
        calendar.navigateToDate([todaysDate.getFullYear(), 1, 1]);
        calendar.selectDate([todaysDate.getFullYear(), 1, 1]);
         
    }



    Regards,
    Viktor Tachev
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jeff
    Jeff avatar
    6 posts
    Member since:
    May 2016

    Posted 03 Jun in reply to Viktor Tachev Link to this post

    That works.  However, when I select another year, it returns back to January 2016.  Is there another function I need to put the code?

    Jeff

  5. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 06 Jun Link to this post

    Hello Jeff,

    Indeed the date will be reverted back to January 1st after post with the current implementation. If you would like to keep the selected date in the calendar you would need to add a condition that checks if there is an already selected date. This way January 1st will not be selected after the user selects a date.

    function clientLoad(sender, args) {
        if (sender.get_selectedDates().length == 0) {
            var todaysDate = new Date();
            var calendar = sender;
     
            calendar.navigateToDate([todaysDate.getFullYear(), 1, 1]);
            calendar.selectDate([todaysDate.getFullYear(), 1, 1]);
        }
    }


    Regards,
    Viktor Tachev
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top