Quantcast
Channel: SCN: Message List - SAPUI5 Developer Center
Viewing all articles
Browse latest Browse all 8124

Re: OData Model and Data Binding

$
0
0

Hi Sandip,

 

to get information on the fields of a particular entity, you might want to make use of the method "getServiceMetadata()" of the oData model. If you "drill" into the "dataServices" object of the result, you will find the metadata of the service including all fields... .

 

To get the number of entries of a collection and the collection is bound to a control, you can use the methods "getBinding('rows').getLength()". Here "rows" is the aggregation that the collection is bound to.

Here is a small example that shows how those methods can be used:

<script>   
 // This function will be called after the data has been read
 function onRequestCompleted(){  // Get the table control from the "core"  var oTable = sap.ui.getCore().byId("idCities");  // Change the title of the table and add the number of rows  oTable.setTitle("Number of cities: "+oTable.getBinding("rows").getLength());
 };     
 var oModel = new sap.ui.model.json.JSONModel();
 // Registration for the RequestCompleted event
 oModel.attachRequestCompleted(onRequestCompleted);
 // Here I'm using a nice freely available service...
 // With the uri below, it will search in the "like" mode vor cities
 // with the name "york"
 var uri = "proxy/http/api.openweathermap.org/data/2.1/find/name?q=york&type=like";
 sap.ui.getCore().setModel(oModel);
 oModel.loadData(uri);

 // The UI contains a table, which only displays the city name
 var oTable = new sap.ui.table.Table("idCities", { 
  visibleRowCountMode : sap.ui.table.VisibleRowCountMode.Auto,  //visibleRowCount: 0,  columns : [    {label: "City", template: "name" },     ]
 });
 oTable.bindRows("/list");

 oTable.placeAt("content");
</script><!-- To show the result of "visibleRowCountMode = auto", the parent of
the table needs to have a defined height --><style>    #content {     height: 600px   }</style>

Regards, Frank


Viewing all articles
Browse latest Browse all 8124

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>