on 10-01-2015 11:24 AM
Hi Community,
I need to your help again.
I have a grid table binded to oDataModel, which is working fine and showing data as expected. Now I need your help to implement the creation of new entry.
Basically, when the user press "Add Cost Type", a new empty row should be added to the bottom of the table. This row should get saved to backend once the user press "save".
I have seen several examples with JSONModel but didn't had much luck with ODataModel. Any help is highly appreciated.
Here is my "Add Cost Type" function:
var oModel = this.getView().getModel();
var rowCount = this.getView().byId("idCostPerUnitsTable").getBinding("rows").getLength();
rowCount = rowCount + 1;
var vProperties = {};
vProperties.SapCostUnitId = rowCount;
alert("row id " + rowCount);
oModel.createEntry("/CostPerUnits", vProperties);
Saqib,
I doubt you can accomplish it from the odata model point of view. as you mentioned, this is easily done on the JSON model as the JSON model is a client side model, however, the odata model is a server side model.
is there a reason why you could not accomplish this via the json model ?
hope this helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it should be very easy:
https://sapui5.hana.ondemand.com/#docs/api/symbols/sap.ui.model.json.JSONModel.html
Thanks, but I have a odata service running in the backend and don't get the data as json. Can I still consume my odata service (https://iccxe61e91fa.neo.ondemand.com/indirect_cost_calculator/odata/CostPerUnits) as json?
Hi Saqib,
Step1:
var getModelData = sap.ui.getCore().getModel("JSONTableModel").getData();
Step2:
var oDataCreateEntry = new sap.ui.model.odata.ODATAModel("ServiceName");
oDataCreateEntry.setHeaders({
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/atom+xml;type=entry; charset=utf-8",
//"X-CSRF-Token" : "Fetch",
"DataServiceVersion": "2.0",
"method": "POST",
});
oDataCreateEntry.create("/CollectionName", getModelData,null,function(){
alert("Successfully created"
});
Thanks,
Karthik A
New question, new Discussion please.
Please mark this Discussion with a Correct Answer (closes, but does not lock the Discussion) and Helpful Answer where appropriate. See http://scn.sap.com/community/support/blog/2013/04/03/how-to-close-a-discussion-and-why Even if you discovered the solution without any outside contributions, it helps others to understand what the solution turned out to be.
Do not use Assumed Answered as it confuses anyone looking for the specific answer. If you dig into the Getting Started link (top right of each SCN page), you are only instructed to mark Helpful or Correct Answers to Discussion responses.
Thanks, Mike (Moderator)
SAP Technology RIG
hmm...
it adds it to
this.oData[sKey] = oEntity;
try to call
oModel.refresh() after you crete and entry to notify bindings?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.