This is a migrated thread and some comments may be shown as answers.
Preselect "today" on initialization
2 Answers 6 Views
This is a migrated thread and some comments may be shown as answers.
Andrey
Top achievements
Rank 1
Andrey asked on 04 Jul 2020, 10:46 AM

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 Answers, 1 is accepted

Sort by
0
Accepted
Svetoslav Dimitrov
Telerik team
answered on 06 Jul 2020, 07:12 AM

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.
0
Andrey
Top achievements
Rank 1
answered on 06 Jul 2020, 11:33 AM

Hi Svetoslav,

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

Thanks!

Asked by
Andrey
Top achievements
Rank 1
Answers by
Svetoslav Dimitrov
Telerik team
Andrey
Top achievements
Rank 1
Share this question
or