Skip to Content
avatar image
Former Member

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

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)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Sep 28, 2017 at 01:15 AM

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

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 24, 2017 at 09:22 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

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

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • 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


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

    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

    Add comment
    10|10000 characters needed characters exceeded