Skip to Content

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



Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Mar 03, 2014 at 07:03 PM

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


    Add a comment
    10|10000 characters needed characters exceeded

    • 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


  • Posted on May 11 at 11:51 AM

    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 "/".

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.