on 09-21-2015 3:45 PM
New to UI5 and attempting to create a table with rows bound to an OData model. One of the columns will be an editable dropdown with list elements populated via a JSON model. How can one bind the dropdown list to the JSON model, but set the selected key to values from the OData table?
I was able to get this working when both the table and dropdown were paths within the same OData model, but the browser was calling the OData service to get the dropdown list for every row in the table so I am now binding the list to a JSON model.
A rough example of what isn't working for me is below. I was assuming this was a matter of using named models and getting the right path syntax, but no luck so far:
var oModel_YN = new sap.ui.model.json.JSONModel();
oModel_YN.setData([{key: "Y", text: "Yes"}, {key: "N", text: "No"}]);
var oDropYN = new sap.ui.commons.DropdownBox({
change: oController.updateService
});
oDropYN.bindItems('MyYN>/', new sap.ui.core.ListItem({key: '{MyYN>key}', text: '{MyYN>text}'}));
oDropYN.setModel(oModel_YN, "MyYN");
oDropYN.bindProperty("selectedKey", "{YN}");
this.oModel = new sap.ui.model.odata.ODataModel("/data/myservice.xsodata", true); // model contains a field YN which should be used for the list element selection
oTable = new sap.ui.table.Table("updateTable", {tableId: "updateTableId", visibleRowCount: 10});
oTable.setModel(this.oModel);
...
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Yes/No}),
template: oDropYN,
...
}));
oTable.setModel(this.oModel).bindRows({
...
Hi Benjamin,
http://jsbin.com/paxihe/2/edit?html,js,output
Try this, it will help you.
Any issues let us know.
Thanks,
Karthik A
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
>>oDropYN.bindProperty("selectedKey", "{YN}");
but where do you set the model for property YN?
having list of values for selector (dropdown or other) from one mode and selected key from another is pretty common, it is never a problem, like:
<Select | |||||
items="{ path : 'CountryRegions>/regions', sorter: { path: 'value' }}" | |||||
selectedKey="{State}" | |||||
visible="{state>/editable}" | |||||
change="regionChanged"> | |||||
<core:Item key="{CountryRegions>key}" text="{CountryRegions>value}" /> | |||||
</Select> |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.