Hi All
I have a dropdown box column displaying in a data table that is bound to a json model. My problem is that the drop down box does not display the correct item from the table, it always shows the first item and not the value that is in the data table
On my model I have a entries node that is bound to the data table rows.
I also have a costcenter node that holds the values of all the cost centers that will appear in the drop down on each row of the table. Each row on the table has a different cost center value and I would like to see its text as the selected item in the drop down box.
Any suggestions or help would be great
When the table is rendered the value in the drop down is always "center 1", as this the first item in the list. What I require is to have the text for the corresponding table field "kostl ".
The example below shows 3 entries on my data table, I would expect to see
Row 1 "cost center 5"
Row 1 "cost center 1"
Row 1 "cost center 2"
{
"costcenter": [
{
"kostl": "ccawg1",
"kostl_desc": "center 1"
},
{
"kostl": "ccawg2",
"kostl_desc": "center 2"
},
{
"kostl": "ccawg3",
"kostl_desc": "center 3"
},
{
"kostl": "ccawg10",
"kostl_desc": "center 10"
}
],
"entries": [ {
"pernr": XXXXXXX1,
"kostl": "ccawg5"
},
"pernr": XXXXXXX2,
"kostl": "ccawg1"
},
"pernr": XXXXXXX3,
"kostl": "ccawg2"
}
]
}
var oDropdownBox1 = new sap.ui.commons.DropdownBox("ddcostctr",{
change: function(oEvent){
// Assigns the key when item is changed
var oKey = oEvent.oSource.getSelectedKey();
var oBindingContext = this.getBindingContext();
oBindingContext.getModel().setProperty("kostl", oKey, oBindingContext);
}})
.bindProperty("value", "kostl") //this has to be value from entries
.bindAggregation("items", "/costcenters", new sap.ui.core.ListItem({
text: "{kostl_desc}",
key: "{kostl}"
}));
var oTable = new sap.ui.table.Table("tblctrl", {
title: "CRUD Application Example",
visibleRowCount: 10,
firstVisibleRow: 0,
selectionMode: sap.ui.table.SelectionMode.Single,
});
// Adding the table columns
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Pernr"}),
template: new sap.ui.commons.Label().bindProperty("text", "pernr"),
sortProperty: "pernr",
filterProperty: "pernr",
width: "50%"
}));
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Cost Centre"}),
template: oDropdownBox1,
width: "75px",
hAlign: "Left"
}));
var oModel1 = sap.ui.getCore().getModel();
oTable.setModel(oModel1);
oTable.bindRows("/entries");
Thanks