This is a migrated thread and some comments may be shown as answers.

DataSource - OData v4 - enums not supported yet?

17 Answers 141 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Casimodo
Top achievements
Rank 1
Casimodo asked on 30 Apr 2015, 08:55 PM

Hi,

I was told to ask here. Enums seem not to be supported by kendo's datasource in conjunction with OData v4 and MVC.

E.g. if I have a nullable enum property on an entity, the following issues arise:

1) The grid won't display values for such types.

2) When editing or adding new records, the datasource becomes confused and sends always the value null to the server.

Workaround:

(told me by one of Telerik's supporters today)

a) Define as foreign key to a list of enum-name/display: E.g.: columns.ForeignKey(m => m.Gender, PickItemsHelper.ToSelectList<PersonGender>(includeNull: true, useNames: true));

b) Define as of type string in the schema -> model : model.Field("Gender", typeof(string));

 

This now works for (1) and (2). I consider this a temporary workaround for a non-implemented part of the OData v4 spec.

However, when applying the workaround an additional issue pops up:

3) When explicitly selecting the null value (i.e. when we have a nullable enum), the datasource now sends an empty string to the server, which rejects the request as invalid because it expects either an enum name or null.

 

Any clues how to work around issue (3)?

 

Best regards,

Kasimier Buchcik

17 Answers, 1 is accepted

Sort by
0
Casimodo
Top achievements
Rank 1
answered on 30 Apr 2015, 09:36 PM

Additionally a fourth issue arises:

4) When the nullable enum's value is null initially and then one tries to edit that value, then any value selection results in the value "[object Object]" being sent by the datasource to the server and rejected. This is similar what happens with nullable GUIDs. But in this case one can not specify a default value as a workaround.

 

Two blockers here.

 

Best regards,

Kasimier Buchcik

0
Casimodo
Top achievements
Rank 1
answered on 01 May 2015, 05:59 PM

I found a workaround for issue (4) here: http://www.telerik.com/forums/dropdownlistfor-return-value-of-object-object-

One has to use ValuePrimitive(true) on the DropDownList.

 

Can't find a solution for issue (3). Kendo still sends an empty string when adding a new record.

I'll try to describe the scenario:

1) Use an entity with a property of type nullable enum

2) Use Web API 2.2, OData v4

3) Use a kendo grid

4) Use a pop up editor template with a DropDownList, use ValuePrimitive(true) and bind to e.g. list of:

{ null, "" }, {"One", "One"}, {"Two", "Two" }

5) Add a new record via the grid. *Don't* change the selection of the enum property (i.e. leave it null)

6) Apply changes

7) Via Fiddler is see that an empty string was sent to the server

7) Server error: "Es müssen gültige Informationen angegeben werden, um die Zeichenfolge einzufügen."

Or english: "Must specify valid information for parsing in the string."

 

Any help here?

 

Best regards,

Kasimier Buchcik

0
Casimodo
Top achievements
Rank 1
answered on 01 May 2015, 07:22 PM
Also the filter displays the entry "[object Object]" when nullable enums are used (see attached image).
0
Casimodo
Top achievements
Rank 1
answered on 02 May 2015, 05:54 PM

I now solved my issue (3) by setting all relevant property values to null in the "edit" event of the grid. Apparently specifying default null values via the html helper is not honored, so one has to set those manually.

By the way: I learned that my issues here are related to all nullable types and are not specific to enums.

Remaining issue: The filters still show the [object Object] entry. Is there an option (like ValuePrimitive(true) for the DropDownList) to let the grid know that it is using a primitive data type for a column?

Feature request:

In a nice world the grid itself could and would inspect the given model type (i.e. via Html.Kendo().Grid<Person>()) and weave the necessary settings for nullable property types. Any plans to automate this for us?

 

Best regards,

Kasimier Buchcik

0
Rosen
Telerik team
answered on 05 May 2015, 07:19 AM
Hi Kasimier,

I'm afraid that setting { null, "" } as a possible filter value is not supported. You should either remove it completely or try using something like { "", " " } or { null, " " } (note the space in the text) instead.

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Casimodo
Top achievements
Rank 1
answered on 05 May 2015, 08:42 PM

Hi Rosen,

Using { null, " " } as you proposed indeed fixes the display of the filter items.

 

Next issues:

1) Unfortunately selecting the null item from the list and then clicking of "filter" does nothing - kendo doesn't filter.

2) Filtering of OData enums doesn't work for me on the ASP.NET side.

See http://forums.asp.net/t/2048750.aspx?Web+API+OData+v4+exception+when+using+enum+filter

Rosen, does filtering of enums work on your side using OData v4?

Best regards & thanks,

Kasimier Buchcik

0
Casimodo
Top achievements
Rank 1
answered on 05 May 2015, 08:47 PM
On (2): I just realized that there's a problem differentiating between a non-selected item and a null item. Does Kendo support filtering using nulls at all?
0
Casimodo
Top achievements
Rank 1
answered on 05 May 2015, 08:48 PM
Correction; the above "On (2)" should read "On (1)".
0
Rosen
Telerik team
answered on 06 May 2015, 12:35 PM
Hello Kasimier,

The null value in the items will match option label of the DropDownList value. This is due to fact that the option label is design to be shown when there is no value (a null).

The actual filtering will depend on how the server will handle the equals filter on a null value  ($filter=Gender+eq+null), as in this scenario such filter expression will be created (see bellow for my  OData v4 findings). Please note the DataSource itself those not provide a IsNull/NotIsNull filter operators. Here is the uservoice entry for adding such support.


Regarding, the OData v4. It seems that it will require spcial handling for filtering on Enums. It is similar to the following:

$filter=MyEnumProp has MyWebApplication.Models.MyExampleEnum'One'

This is not currently supported by our implementation. Note that the DataSource does not have knowledge if given value represents a .NET enum type nor what is the actual server enum type name.

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Casimodo
Top achievements
Rank 1
answered on 07 May 2015, 05:19 PM

Hi Rosen,

Ok, I voted on uservoice.

The "has" operator would only be needed if using [Flags] enums. (http://docs.oasis-open.org/odata/odata/v4.0/odata-v4.0-part2-url-conventions.html). This means, in my case this should work out of the box. Something's wrong on ASP's side.

I opened an issue at https://github.com/OData/odata.net/issues/182

Best regards,

Kasimier Buchcik

0
Casimodo
Top achievements
Rank 1
answered on 07 May 2015, 05:27 PM
And also at OData/WebAPI because I don't know exactly where to put it: https://github.com/OData/WebApi/issues/331
0
Rosen
Telerik team
answered on 08 May 2015, 10:50 AM

Hello Kasimier,

Great, let us know if there is any progress on the issue on OData side.

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Casimodo
Top achievements
Rank 1
answered on 08 May 2015, 04:17 PM

Rosen,

Support for prefix free nullable enum types was not implemented yet in System.Web.OData for this specific scenario. For now I applied the fix locally on my side. Filtering works fine now. And yes, "xyz eq null" works as well.

See https://github.com/OData/WebApi/issues/331

Regards,

Kasimier Buchcik

0
Casimodo
Top achievements
Rank 1
answered on 08 May 2015, 04:25 PM

Rosen,

you can close this thread if you want. With all the mentioned workarounds and fixes applied, I can now use enums with Kendo and OData v4.

Regards & thanks,

Kasimier Buchcik

0
Casimodo
Top achievements
Rank 1
answered on 08 May 2015, 04:33 PM

I added a uservoice entry for the support of the "has" operator.

http://kendoui-feedback.telerik.com/forums/127393-telerik-kendo-ui-feedback/suggestions/7878327-datasource-odata-v4-support-has-operator

0
Casimodo
Top achievements
Rank 1
answered on 12 May 2015, 01:14 PM

Rosen,

the Web API OData fix for nullable enums in filters in now available via the nightly build package:

<package id="Microsoft.AspNet.OData" version="5.6.0-beta1-150511-Nightly" targetFramework="net45" />

0
Rosen
Telerik team
answered on 12 May 2015, 02:27 PM

Hello Casimodo,

This sounds great, thanks for the information.

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Data Source
Asked by
Casimodo
Top achievements
Rank 1
Answers by
Casimodo
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or