cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 Select control not saving data to OData model

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

I have created a full-stack app in Web IDE. I created:

  • HANA table using CDS in data-model.cds.
  • Java-based service that is running.
  • SAPUI5 table that displays the rows and allows editing of multiple rows, then a user pushes Save and it saves all rows by calling submitChanges on the data model

All is OK, except I have now added a column to the table that users a Select control. Here is the XML code:

<m:Select 
   enabled="true" 
   editable="true" 
   forceSelection="false" 
   selectedKey="{status}" 
   items="{ path: 'actions>/Actions' }">
       <c:Item key="{actions>key}" text="{actions>label}"/>
</m:Select>

And here is the controller code.

initActions: function () {
	var actions = {"Actions" : [
		{key: 0, label: ""},
		{key: 1, label: "Keep"},
		{key: 2, label: "Migrate"},
		{key: 3, label: "Delete"}
	]};

	var oModel = new sap.ui.model.json.JSONModel(actions);
	this.getView().setModel(oModel, "actions");
}

When I view the data, and if I change the data directly in the database, I get the right values in the Select box. But if I change the select box and click Save, it does not save the values (in fact, at this point, it doesn;t save any of the data).

I have a default data model (OData data source), whose field is status. The second model holds the choices for the Select control.

Any idea?

Accepted Solutions (0)

Answers (1)

Answers (1)

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

Seems that I need to set the type, since the key in the control is stored as a String but my data type is integer.

<m:Select enabled="true" forceSelection="false" selectedKey="{path: 'status', type: 'sap.ui.model.type.Integer'}" items="{ path: 'actions>/Actions' }" change="selectChange">
       <c:Item key="{actions>key}" text="{actions>label}"/>
</m:Select>

Thanks to pcatano on his post on stackoverflow

https://stackoverflow.com/questions/48145178/sap-m-select-bind-key-as-integer