In SAP UI5, I try to get the data object (in my controller) that is bound to a table row when the user presses it. My view is defined in XML, and my controller is in JS of course.
I have checked How to get content of a row in sap.m.table already but it doesn't work for me, or something is missing.
My view (the relevant part):
<Panel>
<Table id="lineItemList" items="{
path: 'statusJobs>/jobs',
sorter: {
path: 'start',
descending: true
}
}">
<headerToolbar>
<!-- ... -->
</headerToolbar>
<columns>
<Column hAlign="Left" vAlign="Middle">
<Label text="Job" />
</Column>
<Column hAlign="Center" vAlign="Middle">
<Label text="Start" />
</Column>
<Column hAlign="Center" vAlign="Middle">
<Label text="End" />
</Column>
<Column hAlign="Right" vAlign="Middle">
<Label text="Success" />
</Column>
</columns>
<ColumnListItem
type="Navigation"
press=".handleLineItemPress"
>
<Text text="{statusJobs>job}" />
<Text text="{
path: 'statusJobs>start',
formatter:'util.Formatter.Date'}"
/>
<Text text="{
path: 'statusJobs>end',
formatter: 'util.Formatter.Date'}"
/>
<Text text="{statusJobs>status}"/>
</ColumnListItem>
</Table>
The relevant part here is obviously:
<ColumnListItem
type="Navigation"
press=".handleLineItemPress"
>
And in my controller, I have this:
handleLineItemPress: function(evt) {
console.log('evt.getSource: ' + evt.getSource());
console.log('evt.getBindingContext: ' + evt.getSource().getBindingContext());
}
which logs as follows:
evt.getSource: Element sap.m.ColumnListItem#__item11-StatusJobs--lineItemList-0 evt.getBindingContext: undefined
evt.getSource
returns the ColumnListItem, so of course from there, I could use the object hierarchy and fetch the text of a cell, like:
evt.getSource().getCells()[0].getText();
But this does not seem to be the right way and especially does not give the the entire object nor its unique ID, which I happen to not display in the table.
I am somehow missing the connection back to my data model, that I had bound earlier in the code, in the <Table>
item, as follows:
items="{
path: 'statusJobs>/jobs',
sorter: {
path: 'start',
descending: true
}
}"