Save $100 with our Black Friday deals!

Get $100 OFF with promo code BLACKFRIDAY2024 at checkout until November 30.

See Pricing

Still using Radzen Studio?
Achieve more with Radzen Blazor Studio

Radzen Blazor Studio is our new flagship product and vision of how rapid Blazor application development should be done.

Go to Radzen Blazor Studio

Date range filter (Blazor)

This guide shows how to use two DatePicker components to filter DataGrid by date range.

1. Create new CRUD application from our Sample database, open Orders page and add Row component with three Column components with size 5, 5 and 2.

2. Add DatePicker components to first and second column and a Button component to third column.

3. Create start and end properties on page Load and bind DatePicker components Value property to start and end properties.

4. Invoke getOrders() method on Button component Click event with {Filter(start, end)} expression as filter parameter and set getOrdersResult to returned value.

5. Open the Orders.razor.cs file that Radzen has generated for your page to add the Filter method. Radzen generates that file only once and will not overwrite it.

using System;

namespace SampleBlazor.Pages
{
    public partial class OrdersComponent
    {
        string Filter(DateTime? start, DateTime? end)
        {
            return $@"OrderDate >= DateTime(""{GetUTCString(start)}"") && OrderDate <= DateTime(""{GetUTCString(end)}"")";
        }

        string GetUTCString(DateTime? date)
        {
            return date.HasValue ?
                date.Value.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ") : null;
        }
    }
}

6. Run the application and press filter button.