cancel
Showing results for 
Search instead for 
Did you mean: 

How to add new table item without saving it in SAPUI5 app & OData model

ZdenekSmolik
Explorer
0 Kudos

Dear developers,

I have general question regarding very common real scenario with SAPUI5 and SAP NW Gateway.

Let's have sales order object which should be created/maintained using SAPUI5 application.

I tried to solve this task and faced the problem with new item:

  • I have Odata model items bound to the table. It is possible to call createEntry method on Odata items model but till the change is not submitted it is not visible in table.
  • That is why I have to submit every new row to OData model (and SAP backend) which conflicts with single save/cancel approach for both header and items.


How to solve this issue, or do you have another experience?

Thanks Zdenek

Accepted Solutions (0)

Answers (2)

Answers (2)

ZdenekSmolik
Explorer
0 Kudos

Hello Gurus,

really no idea how to maintain ODataModel based table without immediate save to backend? How do you solve such situations? Would it be solution to read data from ODataModel, copy it to JSON model, work on it on the client and than copy it back to ODataModel for subsequent posting? It seems to me to be little bit complicated.

Thanks,

Zdenek

ryan68
Discoverer
0 Kudos

Hello Zdenek Smolík.

Had you found any solution. I need it also. Everybody saying to use JSONModel instead.

Can you please let me know if you found.

ZdenekSmolik
Explorer
0 Kudos

Hello Ryan,

it is pretty old thread but anyway... The problem I had can be resolved using draft concept of Fiori Programming Model. If you are not on the right NW version (I guess 7.51), you can try to implement the "draft" concept, for example by adding "dirty" flag to your database table. It could be true until final save is sent from the frontend.

Hope this helped,

Zdenek

former_member182372
Active Contributor
0 Kudos

do you use v2 odatamodel? server roundtrip shouldnot happen till you call submitUpdate

ZdenekSmolik
Explorer
0 Kudos

Hi Maksim,

thanks for your comment.

yes I use v2 model. I agree that there is no roundtrip till submitChanges() is issued. But no new lines appear in the table. Once submit is executed the CREATE is performed in the backend and table is populated with new data.

And this is basically problem. The user wants to see unsaved data and maybe decide to cancel (rollback) whole transaction. And it is impossible now because potentially unwanted data are already saved in the database.

Thanks,

Zdenek

former_member182372
Active Contributor
0 Kudos

>>. But no new lines appear in the table

is that right?

can you post your code?

ZdenekSmolik
Explorer
0 Kudos

Hi Maksim,

No, it is not right. I'd like to see data in the table without need to submit them to the backend. This is the code run within event handler

onTableItemAddButtonPressed : function(oEvent) {

var _oModel = this.getView().getModel("items");

var _oTable = this.getView().byId("idItems");

var _oEntry = {};

_oModel.createEntry(this.sWorkitemPath + "/ItemSet" ,

     {                   

          success : function() {

          },

          error : function() {

          },

          properties : {

     });

     //   _oModel.submitChanges();

}

Till submitChanges is processed, no data appear in the table despite of being visible in OData property within model instance

After submitChanges data is created in the backend and after that visible in table.

Thanks Zdenek

former_member182372
Active Contributor
0 Kudos

post also the table binding part

ZdenekSmolik
Explorer
0 Kudos

<t:Table id="idItems" title="Items" editable="false" visible="true"

rows="{items>Item}" visibleRowCount="5" selectionBehavior="Row"

selectionMode="Single">

     <t:toolbar>

          <c:Toolbar>

               <c:items>

                    <Button text="+" press=".onAddButtonPressed"

                         enabled="true" />

                    <Button text="-" press=".onDeleteButtonPressed"

                         enabled="true" />

               </c:items>

          </c:Toolbar>

     </t:toolbar>

     <t:columns>

          <t:Column>

               <Label text="Expense Type" />

               <t:template>

                    <Input value="{items>Anln1}" editable="true" />

               </t:template>

          </t:Column>

     </t:columns>

</t:Table>

former_member182372
Active Contributor
0 Kudos

so your binding works for existing data?


what puzzles me - rows="{items>Item}"  is not "/ItemSet"

ZdenekSmolik
Explorer
0 Kudos

Hi Maksim,

yes the binding works on existing data. "Item" is only the name for navigation property. You are right, it should be named ItemSet. Basically the name doesn't influence the behavior.

Thanks and regards,

Zdenek