Declined
Last Updated: 21 Jan 2021 17:56 by René
René
Created on: 21 Jan 2021 13:04
Category: Grid
Type: Bug Report
1
FilterMenuType.CheckBoxList ignores FieldType

If in a grid columns are bound to integer values which shall be treated as enum values it can be done with the FieldType parameter.

Unfortunately the new FilterMenuType.CheckBoxList does not work as expected then.

With

<GridColumn Field="@(nameof(MyModel.MyPropertyId))"
                     FieldType="@(typeof(MyPropertyEnum))"
                     Title="MyProperty"
                     FilterMenuType="@FilterMenuType.CheckBoxList">

the filter shows Integers instead of Enum-Strings.

(With FilterMenuType.Menu the filter correctly treats the values as enums)

Regards,

René

4 comments
René
Posted on: 21 Jan 2021 17:56

Hello Marin,

thank's for this information.

Regards,

René

ADMIN
Marin Bratanov
Posted on: 21 Jan 2021 14:18

Hi René,

The FieldType is used when:

Essentially, it's there so you can tell the grid what the type of the data is when there isn't a way for it to infer the type from the data source.

To filter enums, you must use enum fields, or a custom filter that converts the enum to the underlying field type.

Regards,
Marin Bratanov
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/.

René
Posted on: 21 Jan 2021 13:40

Hello Marin,

thank's for the quick reply.

It makes me wonder though, what the FieldType Parameter is for !? 

If I set Field="@(nameof(MyModel.MyProperty))" the grid always seems to take the correct type from the Model Property.  The FieldType Parameter does not have to be set for that.

So far I only use the FieldType Parameter for overriding integers to enums to get the correct FilterMenu.

Regards,

René

ADMIN
Marin Bratanov
Posted on: 21 Jan 2021 13:30

Hi René,

The FIeldType and the actual type of the column must match. While that could, in some situations, get hacked for an enum and int for the basic filtering modes, I would not recommend it.

The situation with the checklist filter is more complex - it takes the options from the grid data (uses Distinct). Thus, the grid can put in the checkbox list only what you put in its data - and that's an integer now, not an enum.

Thus, you should bind that column to an enum field in order to get the proper filtering, grouping and sorting behavior. If you want more fields to use the same value, you should define them in the model (they could be integers too), and their getters/setters should properly tie them to the enum field they actually describe. Or, you could perform such additional operations only when and where they are needed - e.g., in UI, view-model or in the database only.

Lastly, if you want to keep using an integer with a checklist filter, but to have "meaningful" text for the options, you should build your own filter menu that resembles a checklist, you can find examples in our documentation.

Regards,
Marin Bratanov
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/.