BlazorTable icon indicating copy to clipboard operation
BlazorTable copied to clipboard

Filter cannot handle null values when using JObject

Open vandresen opened this issue 2 years ago • 3 comments

I am using the JObject demo page.

I am setting one of the JObject number to null, column 2 in example below:

var row3 = new JObject(); row3["Column1"] = "A"; row3["Column2"] = null; row3["Column3"] = new JObject(); row3["Column3"]["Name"] = "C"; data.Add(row3);

When I filter on column 2 then I get a exception saying I cannot convert null to double.

vandresen avatar Jul 09 '21 00:07 vandresen

Can you show the <Table> HTML including the relevant column - we can then put a test together and fix. Thanks

conficient avatar Aug 10 '21 08:08 conficient

Here is my whole page:

@page "/"
@using BlazorTable
@using Newtonsoft.Json.Linq

<h1>JObject</h1>

<br />
<Table TableItem="JObject" Items="data" PageSize="15" ColumnReorder="true">
    <Column TableItem="JObject" Title="Column1" Field="@(x => x.Property("Column1").Value.Value<string>())" Type="@(typeof(string))" Sortable="true" Filterable="true" DefaultSortColumn="true" />
    <Column TableItem="JObject" Title="Column2" Field="@(x => x.Property("Column2").Value.Value<int>())" Type="@(typeof(int))" Sortable="true" Filterable="true" />
    <Column TableItem="JObject" Title="Column3" Field="@(x => x.Property("Column3").Value.Value<JObject>().Property("Name").Value.Value<string>())" Type="@(typeof(string))" Sortable="true" Filterable="true" />
    <Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>

@code
{
    private List<JObject> data = new List<JObject>();

    protected override void OnInitialized()
    {
        var row1 = new JObject();
        row1["Column1"] = "B";
        row1["Column2"] = 2;
        row1["Column3"] = new JObject();
        row1["Column3"]["Name"] = "D";
        data.Add(row1);

        var row2 = new JObject();
        row2["Column1"] = "B";
        row2["Column2"] = null;
        row2["Column3"] = new JObject();
        row2["Column3"]["Name"] = "D";
        data.Add(row2);

        var row3 = new JObject();
        row3["Column1"] = "A";
        row3["Column2"] = 3;
        row3["Column3"] = new JObject();
        row3["Column3"]["Name"] = "C";
        data.Add(row3);

        var row4 = new JObject();
        row4["Column1"] = "A";
        row4["Column2"] = 1;
        row4["Column3"] = new JObject();
        row4["Column3"]["Name"] = "C";
        data.Add(row4);
    }
}

I create a new WASM blazor project. Replace the index page with the test code for JObject and set row2["Column2"] = null; as shown above.

vandresen avatar Aug 11 '21 15:08 vandresen

I had a look at this.. don't know how you got the filters to work when the actual column field would result in a NullReferenceException when it tries to get the value:

Field="@(x => x.Property("Column2").Value.Value<int>())"

The value x.Property("Column2") is null, so the expression would result in an error

conficient avatar Sep 11 '21 13:09 conficient