Showing results for 
Search instead for 
Did you mean: 

Get row index when Link control is clicked in table


Hi all,

my UI5 table is made of rows arranged as follows:

Column 1: Link (upon clicking the Link, a ThingInspector will open showing details of the item)

Column 2: Text (short description of the item)

Column 3: Image (upon clicking this Image, the item will be deleted)

If you click on Link for a given row, the selection in the table will not change.

However, I need to be aware of which item is being clicked so that details can be displayed in the ThingInspector.

The only solution I've found is to bind the 'target' property of Link to the 'id' model field. It acts just as a storage for the id value.

When press is triggered on the Link, I check the content of 'target' property of the current link through javascript and act accordingly.

The same problem happens with the Image column.

I guess this is not a good design, but the only alternative I found is to subclass both Link and Image to add a new property, which looks a bit overkill to me.

Can anyone please show the best practice for this scenario in UI5?

Thanks a lot



Accepted Solutions (1)

Accepted Solutions (1)

Active Contributor

On the Press event of the link, you can get the index by



Hi Sandip, thanks for your help.

I integrated your suggestion with a few more tricks:

var eventHandler = function(oEvent) {

  var index = oEvent.getSource().getParent().getIndex();

  var rowContext = oTable.getContextByIndex(index);

  var objId = rowContext.getProperty('id');



I guess that the index in the table is not the same as the index in the model array, since a table can be sorted/filtered.

In addition I think it is much more reliable to use an objId instead of a index, so I retrieve the id of the selected item from the row context, and then work only using the objid as unique reference.

any comment is welcome

Thanks, regards


Answers (1)

Answers (1)

0 Kudos

You can also try:

//getting the Row object

var oSelectedItem = oEvent.getSource().getBindingContext('oModel2').getObject();

var oBindingContext=oEvent.getSource().getBindingContext('oModel2');

//getting the index of the selected row var index=oEvent.getSource().getBindingContext('oModel2').getPath().split("/")[2];

If you trace the oBindingContext you will notice that this has a property sPath which we can use to retrieve the index. The sPath is in the format /ModelDataName/x where x is the index. Hence splitting the path twice by "/".