gustavnavar / Grid.Blazor

Grid component with CRUD for Blazor (client-side and server-side) and ASP.NET Core MVC
GNU Lesser General Public License v2.1
696 stars 134 forks source link

No data displayed when applying an "is null" filter on nullable text columns #381

Closed Zapolatero closed 1 year ago

Zapolatero commented 1 year ago

Describe the bug When applying the filter "isNull" on a nullable text column, no item is returned. This issue happens even if, when no filter is applied on this column, items with a null value on this column are displayed.

To Reproduce This behavior can be reproduced on the autogenerated page on the gridBlazor demo. Steps to reproduce the behavior:

  1. Go to https://gridblazor.azurewebsites.net/autogeneratedcolumns
  2. Click on the "ship name" column to order the grid by ship name, ascending
  3. Check that the grid contains items with a null ship name
  4. Apply a "is Null" filter on the "ship name" column
  5. See that no item is diplayed on the grid

Expected behavior When the grid displays data with a null value on a text column, we expect to see data when applying an "is Null" filter on this column. But the grid is empty when applying such a filter.

Screenshots Items with null values for the "ship name" column are displayed on the grid grid_no_filter

When applying an "is null" filter on the same column, no items are shown : grid_filter

Additional context This issue originates in the way filters are managed in the DefaultColumnFilter.cs class. When applying an "is null" filter on a text column, the sql generated by the Entity Framework to filter data will be as follows :

SELECT [o].[OrderID], [o].[CustomerID], ...
    FROM [Orders] AS [o]
    WHERE ([o].[ShipRegion] IS NOT NULL) AND UPPER([o].[ShipRegion]) = N''

This filter only returns items whose value for the filtered column is an empty, not null string. This is a problem as we would also like to fecth items with a null string.

In order to return data with a null string and data with an empty string for the filtered column, the where clause should be as follows :

WHERE ([o].[ShipRegion] IS NULL) OR UPPER([o].[ShipRegion]) = N''

Bug fix I forked this repository and am currently trying to fix the issue. I will issue a pull request as soon as I find a fix.

Zapolatero commented 1 year ago

I also found that, when applying a not equals filter on a text column, items who have a null string as a value for the filtered column wont be taken in account and wont be displayed. Even if their value is different to the filter's value, as they are null.