Search code examples
sapui5

SAPUI5 Table Get Clicked row data of a multi select enabled table


I have sapui5 table with selection mode Multi Select. I can get selected row data on a Button click event which is in the page.

And also I need to click on a row and get the data of the clicked row. For this I've used ItemPress event.

But I'm unable to get the clicked row data inside the ItemPress Event

This is how I attach the evet

oView.byId("table1").getTable().attachItemPress(this.handleItemPress, this);

The Table

    <Table id="table1" growing="true" growingThreshold="10" mode="MultiSelect">
                            <columns>
                                <Column id="TICKET_ID" hAlign="Begin" vAlign="Top" styleClass="iconCol">
                                    <customData>
                                        <core:CustomData key="p13nData" value='\{"columnKey": "TICKET_ID", "columnIndex":"0", "leadingProperty": "TICKET_ID"}'/>
                                    </customData>
                                    <Text text="{@i18n&gt;Ticket}"/>
                                </Column>
                                <Column id="NUMBER" hAlign="Begin">
                                    <customData>
                                        <core:CustomData key="p13nData" value='\{"columnKey": "NUMBER", "maxLength": "40","columnIndex":"1", "leadingProperty": "NUMBER"}'/>
                                    </customData>
                                    <Text text="{@i18n&gt;NUMBER}"/>
                                </Column>

    </columns>
    <items>
                                <ColumnListItem type="Active">

                                    <cells>
                                        <Text text="{TICKET_ID}"/>
                                        <Text text="{NUMBER}"/>
</cells>
</ColumnListItem>
</Table>

Item Press Event

handleItemPress: function(oEvent) {
        var rowobject = oEvent.getSource().getSelectedItem().getBindingContext().getObject();
    }, 

This gives an error


Solution

  • I think I found a way to access data

    oEvent.getParameter("listItem").getBindingContext().getObject();