Skip to Content
0

Insert delete rows of table binded via aggregation with oData coming from Expand option

Aug 24, 2017 at 12:14 AM

148

avatar image
Former Member

Hi SAP Experts,

My request is pretty easy :

-> Add and delete lines from a table.

Each line of this table is an aggregation of ( RadioButton + 2 ComboBox) like :

The data (MalesionSet) that I bind with this table is coming from a navigation entity ( i.e $expand option )

_onObjectMatched: function(oEvent) {
  // Get the Object Path : 
var sObjectPath = "/Incidents('" + oEvent.getParameter("arguments").Incidents + "')";
  // Get the View to switch to busy when data is loading
	var oView = this.getView();
	var that = this;
  // Bind the view with data
	oView.bindElement({
		path: sObjectPath,
		parameters: {
			expand: "MalesionSet,Equipe_protSet,Equipe_protectionSet,CauseapparenteSet,MesureConserveSet,MatCaussSet"
			},
		events: {
			change: this._onBindingChange.bind(this),
				dataRequested: function() {
						oView.setBusy(true);

Witch means the data has a string format like :

The first binding works correctly, but when I add a new line to the table I have 2 cases :

-> If I use a TwoWay binding :

I get a non working components (Radio button doesn't work & impossible to choose an entry from the combobox)

-> If I use a OneWay binding :

I get a correct line with all components but I can't change the model, that means if I add line and I change the value and then clicked again on add Entries I get 2 empty rows ( my changed values will be lost ).

This is the code that I use for adding the new line :

OnAddClick: function(oEvent) {
  // Get incident number :
var incidNum = this.getView().getModel().getProperty(oEvent.getSource().getBindingContext().getPath()).OvIncident;
  // Get the path of the table data
var sPath = oEvent.getSource().getBindingContext().getPath() + "/MalesionSet";
  // Get the concerned part of Model :
var maLesion = this.getView().getModel().getProperty(sPath);
  // Add an empty line to the table
maLesion.push("MalesionSet(Incident='"+incidNum+"',Lesion='',BodyLesion='')");
  // Update binding 
maLesion.updateBindings(true);
  // Get the table component
var table = this.getView().byId("idmaLesion");
var oTemplate = table.getBindingInfo("items").template;
  // Unbind and bind again the component with oData :
table.unbindAggregation("items");	
table.bindItems(sPath, oTemplate);
}

I tried also to copy the oDataModel to a JsonModel but no way still the same behavior,

So how can I get the entire object from navigation and not only the key string ?

And how can I add and delete the lines of the table like a simple CRUD table ?

Could you please help, thank you in advance.

Best regards,

Zak.

malesion-table.jpg (36.2 kB)
malesion-fe.jpg (38.1 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Jun Wu Sep 28, 2017 at 01:15 AM
2

you can not do that with odata model, you need json model

Share
10 |10000 characters needed characters left characters exceeded
Irfan Gokak Aug 24, 2017 at 09:22 AM
1

Hi,

After adding empty row to model just refresh it. No need to bind it again. Check below code.

// Add an empty line to the table
maLesion.push("MalesionSet(Incident='"+incidNum+"',Lesion='',BodyLesion='')");
this.getView().getModel("YourModelName").refresh();

Hope this will work.

Show 5 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Irfan,

Thank you for your response.

I can't use the refresh() function because it sends data to the back-end and I don't want to sent data to backend until that user clicks on the "Save" button :

Is there any possibility to refresh the model without sending data back to backend ?

Thank you in advance.

Best regards,

Zak

save-button.jpg (48.3 kB)
0

Yes it's possible. First tell me are you loading any data initially to this table?

0
Former Member

Hi Irfan,

This table is binded directly with the data comming from the Odata navigation ( /Incidents('id')/MalesionSet ).

The binding type : TwoWays doesn't work !

Also when we send data to the back-end we can't get the Malesion data table in SAP.

Best regards,

Zak

0

Hi,

I would suggest make odata call from controller and bind it to the table. Then refresh() won't trigger call to backend.

0

please read the api......

0
avatar image
Former Member Oct 10, 2017 at 03:49 PM
0

Hi Jun Wu,

Thank you for your response, you are right it seems that this approche is not supported by OdataV2 as explained in this page :

https://openui5.hana.ondemand.com/docs/topics/6c47b2b39db9404582994070ec3d57a2.html

Do you have an example of an application that communicate with back-end via odata but use json in local biding to tables ?

Thank you in advance.

Best regards,

Zak.

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Zakariae Boubnane ,

Just call the service in the controller using odata model read function , collect the response and set the data of the local json model and attach it to the table .. Means now your table has no connection with the oData model (backend) as json is the client side model . After this just get the binding on add button press add the blank record and attach it to the table binding again either by refreshing the model or rebinding it to the table ..

Thanks

Viplove khushalani

0
Former Member

Hi VIPLOVE KHUSHALANI,

Thank you for your response, please note that I use "xml" technology for the "views", so until now the display works fine as displayed in my first screenshot thanks to the binding in xml code :

<Table class="sapUiSizeCompact" id="maLesionId" items="MalesionSet" mode="Delete" delete="onDeletePressed" visibleRowCount="7" growing="true" growingThreshold="5" >
<headerToolbar>
...

Where :

items="MalesionSet"

is a navigation entity.

Now I understand that I need mixt between Odata and Json model, Odata for the central entity and Json for the navigation entities. I can also get the complete object from Odata and transfer it into Json via the following code in the controller :

_oModel = new JSONModel(this.getView().getModel().getObject(sPath , { expand: "MalesionSet" }).MalesionSet);

But when I try to rebind table with the Json model it doesn't work, neither like this :

var table = this.getView().byId("maLesionId");
table.setModel(_oModel);

nor with this :

var table = this.getView().byId("idFlights2");
table.setModel(_oModel);
var oTemplate = table.getBindingInfo("items").template;
table.bindItems(_oModel , oTemplate);

I think that I need to not bind the model in the xml, but I can't find the correct syntax to do that.

Could you help me please ?

Best regards,

Zak


0
avatar image
Former Member Oct 11, 2017 at 03:21 PM
0

Hi VIPLOVE KHUSHALANI,

Thank you for your response, please note that I use "xml" technology for the "views", so until now the display works fine as displayed in my first screenshot thanks to the binding in xml code :

<Table id="maLesionId" items="MalesionSet" mode="Delete" delete="onDeletePressed" visibleRowCount="7" growing="true" growingThreshold="5" >
<headerToolbar>
...

Where :

items="MalesionSet"

is a navigation entity.

Now I understand that I need mixt between Odata and Json model, Odata for the central entity and Json for the navigation entities. I can also get the complete object from Odata and transfer it into Json via the following code in the controller :

_oModel = new JSONModel(this.getView().getModel().getObject(sPath , { expand: "MalesionSet" }).MalesionSet);

But when I try to rebind table with the Json model it doesn't work, neither like this :

var table = this.getView().byId("maLesionId");
table.setModel(_oModel);

nor with this :

var table = this.getView().byId("idFlights2");
table.setModel(_oModel);
var oTemplate = table.getBindingInfo("items").template;
table.bindItems(_oModel , oTemplate);

I think that I need to not bind the model in the xml, but I can't find the correct syntax to do that.

Could you help me please ?

Best regards,

Zak

Share
10 |10000 characters needed characters left characters exceeded