1

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?

Jaro
  • 1,757
  • 1
  • 15
  • 36
Dilshan
  • 3,231
  • 4
  • 39
  • 50

2 Answers2

3

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");
}
Inizio
  • 2,226
  • 15
  • 18
Nandan Chaturvedi
  • 1,028
  • 3
  • 16
  • 32
  • I had the following issue when I use the similar code earlier. https://github.com/SAP/openui5/issues/393 – Dilshan Sep 03 '18 at 18:16
2

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
 }
}
Inizio
  • 2,226
  • 15
  • 18
  • Thank you for your answer. Doesn't work either. Get the same issue as https://github.com/SAP/openui5/issues/393 :( – Dilshan Sep 06 '18 at 18:13
  • `oTable.getItems()` return only the visible rows, if you want all the rows(items) then you need to get the bind data from the model itself. I will update the code – Inizio Sep 07 '18 at 06:29