Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter cannot handle null values when using JObject #319

Open
vandresen opened this issue Jul 9, 2021 · 3 comments
Open

Filter cannot handle null values when using JObject #319

vandresen opened this issue Jul 9, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@vandresen
Copy link

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 vandresen added the bug Something isn't working label Jul 9, 2021
@conficient
Copy link
Collaborator

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

@vandresen
Copy link
Author

vandresen commented Aug 11, 2021

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.

@conficient conficient self-assigned this Aug 15, 2021
@conficient
Copy link
Collaborator

conficient commented Sep 11, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants