cancel
Showing results for 
Search instead for 
Did you mean: 

read all data from sapui5 table(sap.ui.table.Table)

Former Member
0 Kudos

Hi,

My requirement is to read all data from the table by clicking on the Button. Using the below code we are trying to read all rows in the table.

var oTable = new sap.ui.table.Table({

  title: "",

  id: "datatable",

  visibleRowCount: 5,

  width: "400px",

  firstVisibleRow: 3,

  editable: true,

  });

var bttn= new sap.ui.commons.Button({

  text : "Read Data",

  tooltip : "This is a test tooltip",

  press : function() {

       for(var i=0;i<oTable.getRows().length;i++)

       {

           alert(oTable.getRows()[oTable.getSelectedIndices()[i]].getCells()[1].getText());  // i am unable to display the data  at this statement

       }

                            }

  });

Pls suggest...............

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member182862
Active Contributor
0 Kudos

Is the table bind to a model?

-D

former_member206705
Participant
0 Kudos

Hi Mano,

getSelectedIndices() will return an array of rows which are selected. Not all the rows.

You could instead try this :

oTable.getRows()[i].getCells()[1].getText()

Thanks and best regards,

Shilpa

nabheetscn
Active Contributor
0 Kudos

Hi Mano

This syntax will get you all the rows in the table. Do you want all the rows or selected one only please clarify clearly

sap.ui.getCore().getElementById('T-POhdr-DR').getRows()


Nabheet

Former Member
0 Kudos

Hi All,

The code oTable.getRows()[1].getCells()[1].getText(); is not working.

The above code is working only upto oTable.getRows()[1].getCells()[1] but if i put getText it is showing blank screen.

Event tried sap.ui.getCore().getElementById('T-POhdr-DR').getRows() but it is not working.

blank screen.

Pls suggest

Thanks

Mano

former_member182862
Active Contributor
0 Kudos

Just a note on what you are trying to do here.

You are definitely not on the right track if you going down this path of scanning every cell to get values.

The more effective way is to bind your table to a model.

Just my 2 cents worth

-D

former_member206705
Participant
0 Kudos

What is the data type of the column with index 1? You should use the getter function of the corresponding property of the template control.