Skip to Content
author's profile photo Former Member
Former Member

Problem mit Binding

Hello All,

I have some problem with Binding - Can someone help ?

Table is displayed without data.

Thanks in Advance,

Amyn

Code of Index.html :

<!DOCTYPE html> <html> <head> <!-- Added charset='utf-8' to handle data in various langauges --> <meta http-equiv='X-UA-Compatible' content='IE=edge' charset='utf-8' /> <title>Stock</title> <!-- Load UI5, select gold reflection theme and the "commons" and "table" control libraries --> <script id='sap-ui-bootstrap' type='text/javascript' src='resources/sap-ui-core.js' data-sap-ui-theme='sap_platinum' data-sap-ui-libs='sap.ui.commons,sap.ui.table'></script> <script type="text/javascript"> //Create an instance of the table control var oTable = new sap.ui.table.Table({ title : "Artikel" }); //Define the columns and the control templates to be used oTable.addColumn(new sap.ui.table.Column({ label : new sap.ui.commons.Label({ text : "Material" }), // template : new sap.ui.commons.TextView().bindProperty("Matnr", "Matnr"), template: new sap.ui.commons.TextView({text:"{Material}"}), width : "50px" })); var oModel = new sap.ui.model.json.JSONModel();

var url = 'http://abc.com:8026/sap/opu/odata/SAP/Z_AM_TEST_SRV/MaterialSet'; $.ajax({ url : url, jsonpCallback : 'getJSON', contentType : "application/json", dataType : 'jsonp', success : function(data) { oModel.setData(data); sap.ui.getCore().setModel(oModel); //Create a model and bind the table rows to this model var oModel1 = new sap.ui.model.json.JSONModel(); //Get the material array table from MaterialSet object var aData = oModel.getProperty("d/MaterialSet"); // oModel1.setData({ modelData : aData }); oModel1.setData({ modelData : [ {"Material": ""}] }); oTable.setModel(oModel1); } }); oTable.bindRows("/modelData"); oTable.placeAt('content'); // https://scn.sap.com/thread/3401770 </script> </head> <body class='sapUiBody'> <div id='content'></div> </body> </html>
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on Sep 22, 2015 at 02:41 PM
    <!DOCTYPE html>
    <html>
    <head>
      <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
      <meta charset="UTF-8">
      <title>Hello World App</title>
      <script src="https://sapui5.netweaver.ondemand.com/resources/sap-ui-core.js" type="text/javascript"
      id="sap-ui-bootstrap"
      data-sap-ui-theme="sap_bluecrystal"
      data-sap-ui-libs="sap.ui.commons,sap.ui.table">
      </script>
        <script type="text/javascript">
      var oTable = new sap.ui.table.Table({ title : "Artikel" });  
            
            oTable.addColumn(new sap.ui.table.Column({   
                  label : new sap.ui.commons.Label({ text : "Material" }),   
                    template: new sap.ui.commons.TextView({text:"{matnr}"}),
                    width : "50px" }));  
            var oModel = new sap.ui.model.json.JSONModel({
             d : [ { matnr : "Test" } ]
            });  
            
            oTable.setModel(oModel);
            oTable.bindRows("/d/");   
            oTable.placeAt('content');   
            
      </script>
    </head>
    <body class="sapUiBody" id="content">
    </body>
    </html>
    

    If you take this example you will be able to solve your problem. Take care about the binding path and which model you set 😉

    Regards

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 22, 2015 at 09:13 AM

    Hello,

    Could you please provide us the JSON output file.

    Generally with JSon the result set is something like : "/d/results/" whereas you use :

    var aData = oModel.getProperty("d/MaterialSet");

    Maybe this is the issue.

    Regards,

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Joseph BERTHE

      Name Name Entity type

      MaterialSet Material

      And Metadata:

      -<EntityType sap:content-version="1" Name="Material">

      -<Key>

      <PropertyRef Name="Matnr"/>

      </Key>

      <Property Name="Matnr" sap:label="Material" MaxLength="18" Nullable="false" Type="Edm.String"/>

      <Property Name="Maktx" sap:label="Bezeichnung" MaxLength="40" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false"/>

      </EntityType>

      Thanke for your Help !

  • Posted on Sep 22, 2015 at 11:02 AM

    Can you post error in browser's console?

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 22, 2015 at 03:53 PM

    WHY do use jsonmodel to laod odata?????

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.