jdtcn / BlazorDateRangePicker

A Blazor component for choosing date ranges and dates
MIT License
186 stars 34 forks source link

How to force the second calendar to display next Month in Range When Edit an Item #14

Closed lucianparvu closed 4 years ago

lucianparvu commented 4 years ago

I want to use the DateRangePicker to save the selected range dates into database. It works perfect when I add a new item lets say a Product, but when I edit one ( Go to a new page /Edit?ProductId=1) the second calendar displays the same Month.

Calendar

I am missing something ?

My Code: ` <DateRangePicker @bind-StartDate="StartDate" @bind-EndDate="EndDate" Culture="@(System.Globalization.CultureInfo.GetCultureInfo("ro-RO"))" ApplyLabel="@_SharedLocalizer["Apply"]" CancelLabel="@_SharedLocalizer["Cancel"]">

@code { DateTimeOffset? StartDate { get; set; } = DateTime.Today.AddMonths(-1); DateTimeOffset? EndDate { get; set; } = DateTime.Today.AddDays(1).AddTicks(-1); } protected override async Task OnInitializedAsync() { .... var item = await _Service.GetAtributeValueByID(AtributeValueID.Value); if (Item.FromDate.HasValue) { StartDate = Item.FromDate; } if (Item.ToDate.HasValue) { EndDate = Item.ToDate; } }`

jdtcn commented 4 years ago

Hello, try <DateRangePicker LinkedCalendars="true" .... />

lucianparvu commented 4 years ago

Hi, Thank's for answer.

I have Tried but it is not working correctly with LinkedCalendars="true" , looks to be the same problem

In my opinion the problem is the second calendar because displays the same month. Maybe the End Date should be set in a different way . In My Case Item.FromDate and Item.ToDate are DateTime .

Thank's

jdtcn commented 4 years ago

I've found and fixed the issue, just update the package to version 2.3.0

lucianparvu commented 4 years ago

Yes, It is working now, I have tested it in many situations. Thank's