Unplanned
Last Updated: 17 May 2022 08:28 by ADMIN
Rayko
Created on: 15 Dec 2020 13:08
Category: Grid
Type: Bug Report
5
Correct filter for ExpandoObjects with nullable types

Hi Telerik team,

 

When I want to bind the Blazor Grid to an ExpandoObject I need to assign the FieldType. I know I have to use non-nullable types.

But I want to use nullable types (for example int?) to have a blank cell within the Grid when there is no value for it. With "typeof(int)" instead of "typeof(int?)" every empty cell shows "0" which I don't want.

Is there any chance to let FieldType accept nullable types?

 

Best regards,

Rayko

7 comments
ADMIN
Radko
Posted on: 17 May 2022 08:28

Hi Meindert,

Thank you for the clarification. Indeed, I was able to reproduce the described behavior following the steps you have provided. After having a look, I can confirm this to be the same issue as discussed in this thread already, which stems from the way the DataSource package works with Expandos and nullable types.

I can see you have already voted for its fix and as you are following the thread, you will automatically receive notifications about its progress.

Regards, Radko Stanev Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Meindert
Posted on: 11 May 2022 05:32

Hi Radko,

The data we have to deal with is both "null" and "0" meaning full. Measurement with 0 as result or no measurement done.

The grid itself seems to handle this well on type="decimal". Also the Aggregate.Max shows a value. It seems not logic to use decimal and not decimal? but with expandoobject it works.

Problems are with:
- Filtering on Salary hangs the page;
- Aggregate.Average prevents starting the page, nothing shown.

In your described example you could reproduce this by adding some null values.

decimal salary = (decimal)rand.Next(1000, 5000);
ExpandoObject employee = new ExpandoObject();
employee.TryAdd("Salary", (i > 2 ? salary : null));

After using column type decimal? the Aggregate.Average works fine.

The filtering is still a problem.

Kind regards, Meindert

ADMIN
Radko
Posted on: 10 May 2022 13:55

Hi Meindert,

If I understand correctly, you had to introduce nullable types in order to get the aggregates to work correctly? 

The above-described issue stems from the nullable types themselves and if there is no need for such, the Grid should pick up the correct FilterOperator by itself. We have an example (https://github.com/telerik/blazor-ui/tree/master/grid/binding-to-expando-object) that demonstrates binding to Expando, grouping with aggregates that might be helpful.

If I misunderstood, could you please elaborate more in regards to why nullable types were needed for the aggregates to work?

Regards, Radko Stanev Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Meindert
Posted on: 04 May 2022 05:16

Hi,

We use in our project expando objects and have column types decimal, int, datetime and string. There was no major problem without defined nullable types. 

For aggregation we use decimal? and int? because it seems not to work without it.

Problem now is to get the correct filter ?!

Are there some hints for using expandoobject, aggregation and filtering ?

 

Regards, Meindert

ADMIN
Kristian
Posted on: 29 Dec 2020 15:27

Hello Rayko,

Thank you for the additional information you provide.

I dug more into the case and you are absolutely right - It's a filter issue and the main limitation comes from the way our DataSouce abstraction operates with expando object properties.

I also found that it's possible to extend the current implementation to support nullable value types, so I'm changing the status of the Feature Request to Unplanned and you can Follow its progress on this page.

Regards,
Kristian
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Rayko
Posted on: 21 Dec 2020 16:23

Hi Kristian,

Thank you for your reply!

I already use column templates to populate nullable expandos. But the built-in filter isn't able to handle these. Every column is treated as a string column. Even numeric columns have a "Contains" filter operator available. So every attempt to filter ends up with: Error: System.ArgumentException: Operator 'Contains' is incompatible with operand types 'Int32?' and 'String'

So, it's more or less a filter issue.

And yes, I've already built custom filters to work around this issue. But custom filters cannot be persisted using Json (as I described in another thread).

 

Best regards,

Rayko

ADMIN
Kristian
Posted on: 21 Dec 2020 15:49

Hi Rayko,

Thank you for this feature request.

You are right that it will be really useful if binding the Grid to ExpandoObject could handle nullable types automatically.

We need to investigate deeper if this is doable with the current implementation, though. 

I will gather more information and I will follow up to you and to share the results of the investigation.

 

Until then, I can offer you an easy workaround to show the null values in the columns:

Define templates of your columns that showing the value directly from the current expando object. Here is some sample code:

 

<GridColumn Field="Age" FieldType="@typeof(int?)">
    <Template>
        @(((IDictionary<string, object>)context)["Age"])
    </Template>
</GridColumn>

 

 

Regards,
Kristian
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.