Hello,
If I use a DataGrid with a LoadData delegate and try to filter with a DateTime that goes down to millisecond level of precision, the filter doesn't work.
I believe the issue stems from the GetColumnFilter method in QueryableExtension.cs. On line 465 pf this class, the date time format used does not include the milliseconds:
var dateFormat = dateTimeValue.TimeOfDay == TimeSpan.Zero ? "yyyy-MM-dd" : "yyyy-MM-ddTHH:mm:ssZ";
Code to reproduce is as follows, click the filter button and you'll see it gives no rows in the grid, where it should give one row.
<RadzenButton Text="Filter Data" Click=@OnFilterDataClick />
<RadzenDataGrid @ref="grid" AllowFiltering="true" FilterMode="FilterMode.Advanced" Data="@gridData" TItem="Employee" ColumnWidth="300px" LoadData="LoadData">
<Columns>
<RadzenDataGridColumn TItem="Employee" Property="FirstName" Title="First Name" Width="140px" />
<RadzenDataGridColumn TItem="Employee" Property="LastName" Title="First Name" Width="140px" />
<RadzenDataGridColumn TItem="Employee" FilterProperty="DOB" Property="DOB" Title="DOB" Width="140px">
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
@code {
private IList<Employee> data;
private IList<Employee> gridData;
private RadzenDataGrid<Employee> grid;
private int? count;
protected override void OnInitialized()
{
SetData();
}
private void OnFilterDataClick()
{
var column = grid?.ColumnsCollection.Where(c => c.Title == "DOB").FirstOrDefault();
if (column != null)
{
var filterValue = new DateTime(2023, 1, 1, 14, 0, 0, 10);
column.SetFilterValue(filterValue);
column.SetFilterOperator(FilterOperator.Equals);
}
grid?.Reload();
}
private void SetData()
{
gridData = new List<Employee>() { new Employee() { FirstName = "Peter", LastName = "Smith", DOB = new DateTime(2023, 1, 1) }, new Employee() { FirstName = "Carl", LastName = "BlaBla", DOB = new DateTime(2023, 1, 1, 14, 0, 0, 10) } };
}
private void LoadData(LoadDataArgs args)
{
var query = data?.AsQueryable();
if (!string.IsNullOrEmpty(args.Filter))
{
query = query?.Where(args.Filter);
}
if (!string.IsNullOrEmpty(args.OrderBy))
{
query = query?.OrderBy(args.OrderBy);
}
count = query?.Count();
gridData = query?.ToList();
}
public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime DOB { get; set; }
}
}