Skip to Content

How to bind table data to Odata without selecting row index

Hi Experts,

I want send table data to backend(ODATA) without selecting index.

ex. if have 100 records it should bind at time

i gone through this link

How to send table data to Odata | SCN

here they are sending invidual values and hard coded the data.

i don,t know how to get table data and push it to ODATAModel on click of Button.

Example without using table data:

function batchTest(){

var sServiceUrl = "services/employee.xsodata";

var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true);

var oEmp1 = {

"EmployeeId": "0000000014",

"FirstName": "Laura",

"LastName": "Hahn"

};

var oEmp2 = {

"EmployeeId": "0000000015",

"FirstName": "Matthias",

"LastName": "Müller"

};

var batchChanges = [];

batchChanges.push( oModel.createBatchOperation("Employees", "POST", oEmp1) );

batchChanges.push( oModel.createBatchOperation("Employees", "POST", oEmp2) );

oModel.addBatchChangeOperations(batchChanges);

oModel.submitBatch(function(data) {

oModel.refresh();

if (data.__batchResponses[0].__changeResponses) {

alert("Inserted " + data.__batchResponses[0].__changeResponses.length + " Employee(s)");

} else {

alert(data.__batchResponses[0].message);

}

}, function(err) {

alert("Error occurred", err);

});

}

var oButton = new sap.m.Button({

text : "Batch Input",

tooltip : "trigger batch input",

press : batchTest

});

Thanks & Regards,

Venkat

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 21, 2015 at 07:27 AM

    Hi,

    With the getItems() method you get an array of all the rows in your table.

    e.g. var allItems = oTable.getItems();

    var firstItem = allItems[0];

    Now if you want the values of a row you can use the getCells() method.

    e.g.

    var firstColumnOfFirstRow = firstItem.getCells()[0];

    var oEmp1 = {

    "EmployeeId": firstItem.getCells()[0],

    "FirstName": firstItem.getCells()[1],

    "LastName": firstItem.getCells()[2]

    };

    If you want to get all row data, use a for loop:

    JavaScript for Loop

    Kind regards,

    RW

    Add a comment
    10|10000 characters needed characters exceeded

    • Personally, I would never ever use getCells()... Rather use the model property directly:

      var aTableData = this.byId("myTable").getModel().getData();
      
      
      
      for (i = 0; i < aTableData.length; i++) {
          var oEmp = {
              "EmployeeId" : aTableData[0].EmployeeId,
              "FirstName"  : aTableData[0].FirstName,
              "LastName"   : aTableData[0].LastName
          };
          batchChanges.push(oModel.createBatchOperation("Employees", "POST", oEmp));
      }
      

      (I assumed your table data uses the same property names as the POST data)

  • Posted on Sep 21, 2015 at 09:36 AM

    Thank you guys

    😊

    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.