angulardevextreme-angular

enum value in edit form not set


I have a grid with some data (in the stackblitz example one row). The data model is a document, which has priority and currency properties. I realize this properties with enums. Then I convert this enums into arrays in order to use they as data source for devextreme selectbox components.

Clicking on the row, the edit button changes it's state to enabled. Clicking on the edit button, a popup with a form is showing. The currency value in the select box is correctly set, but the priority doesn't. And I really don't understand, why?

You can find the stackblitz example here: https://stackblitz.com/edit/angular-dxpopup-3y6h4h


Solution

  • Object.entries() provide keys and values as strings. So, the convertEnumToArray should cast the key to number using a + as follows,

     convertEnumToArray(enumName: any, pipe: any) {
        return Object.entries(enumName).filter(e => !isNaN(e[0] as any))
              .map(e => ({ id: +e[0], value: new pipe()
              .transform(enumName[e[1].toString()]) }));
     }
    

    Here is the StackBlitz