Preselect "today" on initialization

3 posts, 1 answers
  1. Andrey
    Andrey avatar
    47 posts
    Member since:
    Jul 2014

    Posted 04 Jul Link to this post

    Hi,

    I have a calendar control with initial date. It could be "Today" or any other date. The Calendar works fine but the initial date is not visually selected. If I click on any date it's get selected and displayed in "red" but I need it selected initially without user intervention.

                                    <TelerikCalendar SelectionMode="@CalendarSelectionMode.Single"
                                                     ValueChanged="@( (DateTime d) => OnBeginDateChangeHandlerAsync(d) )"
                                                     Min="@beginmin" Max="@beginmax"
                                                     @bind-Date="@begindate">
                                    </TelerikCalendar>

    @code {
        protected DateTime begindate { get; set; } = DateTime.Now.AddDays(-8).Date;

    }

    Thanks.

  2. Answer
    Svetoslav Dimitrov
    Admin
    Svetoslav Dimitrov avatar
    144 posts

    Posted 06 Jul Link to this post

    Hello Andrey,

    You can preselect the desired date by setting the Value field of the Calendar. You can read more information on our documentation and you can see a sample code snippet on how to do that below:

    <TelerikCalendar SelectionMode="@CalendarSelectionMode.Single"
                     ValueChanged="@( (DateTime d) => OnBeginDateChangeHandlerAsync(d) )"
                     Value="@begindate"
                     @bind-Date="@begindate">
    </TelerikCalendar>
    
    @code {
        protected DateTime begindate { get; set; } = DateTime.Now.AddDays(-8).Date;
    
        async Task OnBeginDateChangeHandlerAsync(DateTime date)
        {
            await Task.Delay(20);
    
            begindate = date;
        }
    }

    Regards,
    Svetoslav Dimitrov
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
  3. Andrey
    Andrey avatar
    47 posts
    Member since:
    Jul 2014

    Posted 06 Jul in reply to Svetoslav Dimitrov Link to this post

    Hi Svetoslav,

    My bad! I expected that the @bind-Date="@begindate" will do the work.

    Thanks!

Back to Top