I have created a responsive sap.m.table. But am not able to load values from the data Object. I want to laod the "subvariants" array of objects.Pls help
summaryDetailData={"subvariants":[{"currentValue":"","Article":"1234567","question":"Carpet Installation type"},{"currentValue":"","question":"CarpetQuantity"},{"currentValue":"","Article":"1234568","question":"Underpad type"},{"currentValue":"","question":"UnderpadQuantity"},{"currentValue":false,"Article":"1234568","question":"Rapid Install"}]}
var oTable = new sap.m.Table("idRandomDataTable", {
headerToolbar: new sap.m.Toolbar({
content: [
new sap.m.Label({text: "Summary Data"}),
new sap.m.ToolbarSpacer({}),
new sap.m.Button("idPersonalizationButton", {
icon: "sap-icon://person-placeholder"
})]}),
columns: summaryDetailData.cols.map(function (colname) {
return new sap.m.Column({ header: new sap.m.Label({ text: colname })})
})
});
oTable.setModel(new sap.ui.model.json.JSONModel(summaryDetailData));
oTable.bindAggregation("subvariants", "/subvariants", new sap.m.ColumnListItem({
cells: oData.cols.map(function (colname) {
return new sap.m.Label({ text: "{" + colname.toLowerCase() + "}" })
})
}));
The way you bind the model to the table is not completely correct. You have to use bindItems
to dynamically bind the table rows (items) to a model. The columns
aggregation is used to define the column layout of the table whereas the items
aggregation is responsible for the table records.
In your case I would create the columns in the control definition and bind the items to the model with your own template.
This should do what you´ve expected (tested it):
var oTable = new sap.m.Table("idRandomDataTable", {
headerToolbar : new sap.m.Toolbar({
content : [ new sap.m.Label({
text : "Summary Data"
}), new sap.m.ToolbarSpacer({}), new sap.m.Button("idPersonalizationButton", {
icon : "sap-icon://person-placeholder"
}) ]
}),
columns : [ new sap.m.Column({
width : "2em",
header : new sap.m.Label({
text : "Current Value"
})
}), new sap.m.Column({
width : "2em",
header : new sap.m.Label({
text : "Article"
})
}), new sap.m.Column({
width : "2em",
header : new sap.m.Label({
text : "Question"
})
}) ]
});
oTable.bindItems("/subvariants", new sap.m.ColumnListItem({
cells : [ new sap.m.Text({
text : "{currentValue}"
}), new sap.m.Text({
text : "{Article}"
}), new sap.m.Text({
text : "{question}",
}), ]
}));
oTable.setModel(new sap.ui.model.json.JSONModel(summaryDetailData));
Hopefully this helps you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With