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

Enum as data parameter

3 Answers 690 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Dang
Top achievements
Rank 1
Dang asked on 18 May 2020, 10:30 PM
Is it possible to pass an enum as the data to the DropDownList? While testing I'm receiving an error [ERROR TypeError: "this.data.slice is not a function"].

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 20 May 2020, 08:21 AM

Hi Corey,

In general, the DropDownList supports binding to an array of values only. The list can consist of primitive values or complex objects. For more details please check the following article from our documentation:

https://www.telerik.com/kendo-angular-ui/components/dropdowns/dropdownlist/data-binding/

Let me know if I can provide any further assistance.

Regards,
Martin
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Dang
Top achievements
Rank 1
answered on 20 May 2020, 01:19 PM
I build a helper method that will convert my enum to an object. I was hoping to avoid using a helper method, but this solution works fine. This will filter out all values where the key is not a number and map the enum to an object with key and text properties.

public convertEnumToObject(e: any): Object[] {
    return Object.keys(e)
      .filter(key => !isNaN(key[0] as any))
      .map(key => ({ value: key, text: e[key] }));
}
0
Martin
Telerik team
answered on 22 May 2020, 06:49 AM

Hi Corey,

Thank you for the provided code snippet.

I am glad to hear that you have managed to resolve the discussed issue. Indeed in this situation using such a helper method is the way to go, considering the type of object that the DropDownList supports. 

Regards,
Martin
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
DropDownList
Asked by
Dang
Top achievements
Rank 1
Answers by
Martin
Telerik team
Dang
Top achievements
Rank 1
Share this question
or