BlazorTable icon indicating copy to clipboard operation
BlazorTable copied to clipboard

[Bug] Filter on DateTime column not working

Open YongQuan-dotnet opened this issue 4 years ago • 2 comments

Describe the bug Filtering on DateTime column does not work. I have also directly run the repo in local, and found the Filtering on DateTime does not work either.

To Reproduce to create a simple page can reproduce

@page "/test"
@using BlazorTable
<div>
    <Table TableItem="TestData" Items="TestDatas" PageSize="10">
        <Column TableItem="TestData" Title="Id" Field="@(x => x.Id)" Sortable="true" Filterable="true" Width="auto" />
        <Column TableItem="TestData" Title="Event DateTime" Field="@(x => x.EventDate)" Sortable="true" Filterable="true" Width="auto">
		</Column>
    </Table>
</div>

@code {     
    public List<TestData> TestDatas { get; set; } = new List<TestData>
    {
        new TestData {Id = 1, EventDate = DateTime.Now },
        new TestData {Id = 2, EventDate = DateTime.Now.AddDays(1)},
        new TestData {Id = 3, EventDate = DateTime.Now.AddDays(2)},
        new TestData {Id = 4, EventDate = DateTime.Now.AddDays(3)},
        new TestData {Id = 5, EventDate = DateTime.Now.AddDays(4)},
        new TestData {Id = 6, EventDate = DateTime.Now.AddDays(5)}
    };

    public class TestData
    {
        public int Id { get; set; }
        public DateTime EventDate { get; set; }
    }
}

Expected behavior filtering on DateTime column can work

YongQuan-dotnet avatar Sep 04 '21 09:09 YongQuan-dotnet

Having a look at this.

The filter for dates does work provided the value is exact: image

..or if you used a Greater Than or Less Than this does work: image

In your sample you're using a DateTime value with a time element. In this case a value of 2021-09-12T15:16:00Z won't be equal to 2021-09-21T00:00:00Z - these are not the equal.

I assume you'd like a date "Is Equal To" to apply a range, e.g. >= 2021-09-12 && < 2021-09-13 ?

I'd need to discuss with @IvanJosipovic to see if that is a good idea.

conficient avatar Sep 12 '21 14:09 conficient

Extending the example of @JamesGit-hash with DateTime?, I noticed that the filter is not properly working.

Having the simple page

@page "/test"
@using BlazorTable

<div>
    <Table TableItem="TestData" Items="TestDatas" PageSize="10">
        <Column TableItem="TestData" Title="Id" Field="@(x => x.Id)" Sortable="true" Filterable="true" Width="auto" />
        <Column TableItem="TestData" Title="Event DateTime" Field="@(x => x.EventDate)" Sortable="true" Filterable="true" Width="auto">
		</Column>
    </Table>
</div>

@code {     
    public List<TestData> TestDatas { get; set; } = new List<TestData>
    {
        new TestData {Id = 1, EventDate = DateTime.Now },
        new TestData {Id = 2, EventDate = DateTime.Now.AddDays(1)},
        new TestData {Id = 3, EventDate = DateTime.Now.AddDays(2)},
        new TestData {Id = 4, EventDate = DateTime.Now.AddDays(3)},
        new TestData {Id = 5, EventDate = DateTime.Now.AddDays(4)},
        new TestData {Id = 6, EventDate = DateTime.Now.AddDays(5)},
        new TestData {Id = 7, EventDate = null},
    };

    public class TestData
    {
        public int Id { get; set; }
        public DateTime? EventDate { get; set; }
    }
}

When filtering for "Is not null" everything seems to be good. GitHub_Bug352_IsNotNull

But, when going to filter the events not having a date set, event with id 7 cannot be found. GitHub_Bug352_IsNull

skyfrog4fun avatar Mar 31 '22 09:03 skyfrog4fun