jdtcn / BlazorDateRangePicker

A Blazor component for choosing date ranges and dates
MIT License
182 stars 35 forks source link

Use a ButtonsTemplate with AutoApply=true #74

Closed pelshen-bankuet closed 2 years ago

pelshen-bankuet commented 2 years ago

I've got a case where I want the AutoApply behaviour, but I want the user to be able to clear the dates with a button (no other buttons required). I can create the button required in the ButtonTemplate but of course it doesn't show up when AutoApply is set to true. Is there any way to do what I want or for a change to be made to make it possible?

jdtcn commented 2 years ago

This can be done without any problems, since the buttons are simply hidden using a css rule, you just need to redefine it in your component:

<style>
    .daterangepicker.auto-apply .drp-buttons {
        display: block;
    }
</style>
It will look something like this ```razor @code { DateRangePicker Picker; DateTimeOffset? StartDate { get; set; } DateTimeOffset? EndDate { get; set; } async Task ResetClick(MouseEventArgs e, DateRangePicker picker) { StartDate = null; EndDate = null; // Close the picker await Picker.Close(); // Fire OnRangeSelectEvent await Picker.OnRangeSelect.InvokeAsync(new DateRange()); } } ```
pelshen-bankuet commented 2 years ago

I see, thank you for the reply, that works, very straightforward!