getContextByIndex doesn't return all the columns

689 Views Asked by At

I have following code

oTableEntry = this.getView().byId("oTable");
var count = oTableEntry._getRowCount();
var oTData;

for (var i = 0; i < count; i++) {
    oTData = oTableEntry.getContextByIndex(i).getObject();

oTData doesn't contain values for all the columns even though they appear in the table. Am I doing something wrong here?

2

There are 2 best solutions below

1
On

I think you are trying to get the table columns and their values for each row. Here is how you can do this:

var oTable = this.getView().byId("oTable");//Get the table by Id    
var aItems = oTable.getAggregation("items");//get the items of the table
for (var i=0; i<aItems.length; i++) {
  var tableColumns = aItems[i].getAggregation("cells");     //Here tableColumns will    //have all the columns of the table rows. 
  var column1Value = tableColumns[1].getProperty("text");
}

2
On

Hope you are looking for same solution!!

var oTable = sap.ui.getCore().byId("YourTableID");
if (oTable) {
 var oColumns = oTable.getColumns();//get all columnms
 var oRows = oTable.getItems();
 for (var r in  oRows) {
    var oRow = oRows[r];
    console.log(oRow.getBindingContext().getObject());//return the row data
 }
}