cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in binding array to table from Component.js

Former Member
0 Kudos

Hi Experts,

I have got my oModel data in an array in the Component.js file. I have returned the array with an entity collection (PFA) and have bind the entity to the table with the code

aData = this.getOwnerComponent().getServiceRequestCollection();

  console.log("table array", aData);

  var oVizFrame3Model = new sap.ui.model.json.JSONModel(aData);

  var oTable = oView.byId("idServiceTable");

  oTable.setModel(oVizFrame3Model);

The table is displayed empty and from the console I found that "table array" is undefined. Some quick suggestions as to how to bind the data to the table would be really helpful.

Thanks,

Srinivasan

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Any suggestions from other experts in the forum would be very helpful.

venkatachala_ck
Active Participant
0 Kudos

Hi Srinivasan,

Try This code

etServiceRequestCollection: function() {

  var oModel = new sap.ui.model.odata.ODataModel("/sap/c4c/odata/v1/c4codata/");

  oModel.read("/ServiceRequestCollection?$filter= CustomerID eq '1001192'",{

  success: function(oData, response) {

  var jsonModel = new sap.ui.model.json.JSONModel({oData.results} )

  sap.ui.getCore().setModel(jsonModel);

  });

  },

For  in ur table try like this

<Table id="idServiceTable" inset="false"

  items="{path:'/', sorter : { path: 'ID'} }">

or

<Table items="{/}" >

if any errors post it.

Thanks & Regards

Venkat

Former Member
0 Kudos

Hi Venkat,

Thank you for the reply. I have altered the code as you have suggested and further added below code

getServiceEntity: function() {

  var aData = {service:this.getServiceRequestCollection()};

  return aData;

  },

I am able to get the array, but the EntityCollection(service) is undefined. Below is the code I tried to get the array in the controller

aData = this.getOwnerComponent().getServiceEntity();

  console.log("table array", aData);

  var oVizFrame3Model = new sap.ui.model.json.JSONModel(aData);

  var oTable = oView.byId("idServiceTable");

  oTable.setModel(oVizFrame3Model);

Regards,
Srinivasan

Former Member
0 Kudos

Hi Venkat,

Any suggestions from your side regarding this?

Regards,

Srinivasan

venkatachala_ck
Active Participant
0 Kudos

Hello Srini,

Please try my above code it will work properly.

Thanks

Venkat

Former Member
0 Kudos

Hi Venkat,


The altered the code in my Component.js file as you have suggested is put below


getServiceCollection: function() {

     var oModel = new sap.ui.model.odata.ODataModel("/sap/c4c/odata/v1/c4codata/");

    oModel.read("/ServiceRequestCollection?$filter= CustomerID eq '1001192'", {

          success: function(oData, response) {

          var oResult = new sap.ui.model.json.JSONModel({service:oData.results});

          sap.ui.getCore().setModel(oResult);

          }

     });

}

I got this model in my controller using the code sap.ui.getCore().getModel(); and have altered the table code as suggested.

Still I am facing the same issue. Hope I have not committed a silly mistake.

Please point it out if you find any.

Thanks,

Srinivasan

Former Member
0 Kudos

Hi,

It would be very helpful if the experts provide some suggestions regarding the same.

Thanks in advance,

Srinivasan

junwu
Active Contributor
0 Kudos

man can u paste ur code here

don't waste other's time to download

even you make it as attachment, please copy the well formatted code.....

junwu
Active Contributor
0 Kudos

just put the data in model, you will get it

you are returning data from success function....no one is going to receive it.

Former Member
0 Kudos

Thank you Jun, I will keep this in mind for any future posts.

The code where the odata is got in an array.

getServiceRequestCollection: function() {

  var oModel = new sap.ui.model.odata.ODataModel("/sap/c4c/odata/v1/c4codata/");

  sap.ui.getCore().setModel(oModel);

  oModel.read("/ServiceRequestCollection?$filter= CustomerID eq '1001192'",{

  success: function(oData, response) {

  var oResult = [];

  oResult = oData.results;

  oResult = {service:oResult};

  return oResult;

  }

  });

  },

The code to bind it with the table:

oResult = this.getOwnerComponent().getServiceRequestCollection();

  console.log("table array", oResult);

  var oVizFrame3Model = new sap.ui.model.json.JSONModel(oResult);

  var oTable = oView.byId("idServiceTable");

  oTable.setModel(oVizFrame3Model);

Former Member
0 Kudos

Have returned the data without the success function. Still the table is empty. Below is the console for the reference.

junwu
Active Contributor
0 Kudos

table code.......

Former Member
0 Kudos

Have built the table in xml view

<Table id="idServiceTable" inset="false"

  items="{path:'/service', sorter : { path: 'ID'} }">

  <columns>

  <Column>

  <Text text="Service Order"/>

  </Column>

  <Column>

  <Text text="Product"/>

  </Column>

  <Column>

  <Text text="Serial ID"/>

  </Column>

  <Column>

  <Text text="Status"/>

  </Column>

  </columns>

  <items>

  <ColumnListItem type="Navigation" press="toDetail">

  <cells>

  <Text text="{ID}"/>

  <Text text="{ProductID}"/>

  <Text text="{SerialID}"/>

  <Text text="{ServiceRequestLifeCycleStatusCodeText}"/>

  </cells>

  </ColumnListItem>

  </items>

  </Table>

junwu
Active Contributor
0 Kudos

if u look at it, it is your data.........

Former Member
0 Kudos

I am having a look at it still no clue on how to proceed.

junwu
Active Contributor
0 Kudos

where is ur array data.......

Former Member
0 Kudos

oModel.read("/ServiceRequestCollection?$filter= CustomerID eq '1001192'", function(oData) {

    var oResult = [];

  oResult = oData.results;

  oResult = {service:oResult};

  return oResult;

  }

  });

This is the array I return from the component