Search code examples
sapui5

How to get the details of the pressed list Item?


I've build a table, that it looks as following:

enter image description here

and the code:

<ColumnListItem type="Detail" detailPress="onDetailPress">
    <cells>
        <ObjectIdentifier title="{Customer>CustomerID}" text="{Customer>CompanyName}"/>
        <Text text="{Customer>ContactName}"/>
        <Text text="{Customer>Address}"/>
        <Text text="{Customer>City}"/>
    </cells>
</ColumnListItem> 

When I press on the pencil, it will emit the event detailPress:

    onDetailPress: function(oEvent) {
        console.log(oEvent.getParameters());
    } 

What is the return type getParameters() method call on the event object? The doc does not mention any type.

How can I get the Customer details of the pressed list item using the oEvent.

The debugger says:

enter image description here


Solution

  • you can get the object that is bound to the row like this

    onDetailPress: function(oEvent) {
        var oObject = oEvent.getSource().getBindingContext("Customer").getObject();
        // from this object, you can do oObject.CustomerID
    }