softshipper
softshipper

Reputation: 34071

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

Upvotes: 0

Views: 4034

Answers (3)

We can get the row object by accessing the getSource of oEvent object:

oEvent.getSource().getBindingContext("Customer").getObject();

Upvotes: 0

D. Seah
D. Seah

Reputation: 4592

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
}

Upvotes: 3

The oEvent is the event object. getParameters() returns a JSON Object. So the type is Object as stated here

In this case it is an empty object, but there are other event which return parameters inside the object like for example this one

If you want to get the customerID just get the model path from the clicked row and get the property from the model. Here the snippet:

onDetailPress: function(oEvent){
    var oColumnListItem = oEvent.getSource();
    var sPath = oColumnListItem.getBindingContext("Customer").getPath();
    var sCustomerIDPath = sPath + "/CustomerID";
    var oModel = oColumnListItem.getModel("Customer")
    console.log(oModel.getProperty(sCustomerIDPath));
}

Upvotes: 1

Related Questions