cancel
Showing results for 
Search instead for 
Did you mean: 

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

0 Kudos

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.

Accepted Solutions (0)

Answers (4)

Answers (4)

junwu
Active Contributor

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

irfan_gokak
Contributor

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.

0 Kudos

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

irfan_gokak
Contributor
0 Kudos

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

0 Kudos

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

irfan_gokak
Contributor
0 Kudos

Hi,

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

junwu
Active Contributor
0 Kudos

please read the api......

0 Kudos

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

0 Kudos

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.

former_member340030
Contributor
0 Kudos

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 Kudos

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