on 09-21-2015 8:12 AM
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
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:
Kind regards,
RW
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the snippet
var oEmp1 = {
"EmployeeId": firstItem.getCells()[0],
"FirstName": firstItem.getCells()[1],
"LastName": firstItem.getCells()[2]
};
you have created object (oEmp1 ) and pushing it.
what i meant is your object is only used for first row data so
if i want second row data then i have to create one more object like oEmp2
and push it again?
like that if have 100 records in table is there any necessary to create that much objects and push?
for that purpose i'm asking you "how to push complete table data using single Object."
And that's why you have to use a for loop
for (i = 0; i < allItems.length; i++) {
var item = allItems[i];
var oEmp = {
"EmployeeId": item.getCells()[0],
"FirstName": item.getCells()[1],
"LastName": item.getCells()[2]
};
batchChanges.push( oModel.createBatchOperation("Employees", "POST", oEmp) );
}
There's probably another way to do the same, but this is how I do it
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)
Thank you guys
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.