Hello,
Is it possible to get the name of the DateRangePickerPreset selected. I can get the date ranges that would represent the last 90 days for example but I need to persist the choice so that it can be used again in the future i.e last 90 days from whatever the future date is
For example if the user selected '90 days' from the DateRangePickerPresets below can one somehow see this was a preset and not a custom selection where the date range of the last 90 days was manually selected.
(I don't understand why but the code and screenshot are not showing up below but they did on the original unedited version??)
<SfDateRangePicker>
<DateRangePickerPresets>
<DateRangePickerPreset Label="Last 30 days" Start="@last30daysStart" End="@last30daysEnd"></DateRangePickerPreset>
<DateRangePickerPreset Label="Last 90 days" Start="@last90daysStart" End="@last90daysEnd" />
</DateRangePickerPresets>
<DateRangePickerEvents ValueChange="onValueChanged"></DateRangePickerEvents>
</SfDateRangePicker>
@code{
public DateTime last30daysStart { get; set; } = DateTime.Now.AddDays(-30);
public DateTime last30daysEnd { get; set; } = DateTime.Now;
public DateTime last90daysStart { get; set; } = DateTime.Now.AddDays(-30);
public DateTime last90daysEnd { get; set; } = DateTime.Now;
public void onValueChanged(RangeEventArgs args)
{
if(args.StartDate.Date == last30daysStart.Date && args.EndDate.Date == last30daysEnd.Date)
{
Console.WriteLine("Last 30 days chosen");
}
else if(args.StartDate.Date == last90daysStart.Date && args.EndDate.Date == last90daysEnd.Date)
{
Console.WriteLine("Last 90 days chosen");
}
}
} |
var isClick = false;
window.OnSelect = (id) => {
return isClick;
};
window.OnCreated = (id) => {
document.getElementById(id).ej2_instances[0].open = function (e) {
var list = document.getElementById(id).ej2_instances[0].popupObj.element.querySelectorAll('.e-list-item');
for (var i = 0; i < list.length; i++) {
if (!list[i].id.includes("custom_range")) {
list[i].addEventListener('click', function (e) {
isClick = true;
});
}
}
}
};
|
public async Task onRangeSelected(RangeEventArgs args)
{
isPresetClick = await JSRuntime.InvokeAsync<Boolean>("OnSelect", dateRangeObj.ID);
if (args.StartDate.Date == last3daysStart.Date && args.EndDate.Date == last3daysEnd.Date && isPresetClick)
{
Console.WriteLine("Value choosen using the presets");
}
else if (args.StartDate.Date == last3daysStart.Date && args.EndDate.Date == last3daysEnd.Date && !isPresetClick)
{
Console.WriteLine("Value choosen by manually");
}
} |