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
0
Martin Bechev
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:
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.
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[] {
returnObject.keys(e)
.filter(key => !isNaN(key[0] as any))
.map(key => ({ value: key, text: e[key] }));
}
0
Martin Bechev
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.