Return to the controller of odataBasic
from the previous tutorial and replace the following lines:
With the following code:
function fnLoadMetadata() {
try {
oTable.setModel(bpModel);
oTable.setEntitySet("BusinessPartners");
var oMeta = bpModel.getServiceMetadata();
var headerFields = "";
for (var i = 0; i < oMeta.dataServices.schema[0].entityType[0].property.length; i++) {
var property = oMeta.dataServices.schema[0].entityType[0].property[i];
headerFields += property.name + ",";
}
oTable.setInitiallyVisibleFields(headerFields);
} catch (e) {
console.log(e.toString());
oDataFailed();
}
}
bpModel.attachMetadataLoaded(bpModel, function () {
fnLoadMetadata();
});
fnLoadMetadata();
You can see the new function that retrieves the metadata from the service, loops at the results and concatenates the names of the fields separated by a comma. The fields are then attached to the bpModel
component.