Reputation: 119
I have created a table in sapui5 in which data is populating from back end that is SAP Gateway. I have added a column in the table which contains a link. Each row has a link. If I click on that link, a popup box is opened. I want to pass the details of other columns of the same row whose link is selected in the popup box. And to get the details, I need the index of that row which I don't know.
How to achieve it ?
Upvotes: 3
Views: 19059
Reputation: 444
Get the model that you have bound to the table
var model=that.getView().getModel("ModelName");
var path = evt.getSource().getParent().getBindingContextPath();
var data=model.getProperty(path);
data should have the object that you have bound to the row and contains all the values you needed.
Upvotes: 1
Reputation: 4920
I had more or less the same question but with RowRepeater control instead of Table. Have a look at the answer Jasper_07 provided at https://stackoverflow.com/a/21600210/3270057
This will give your access to the current binding context properties, or the whole object
Hope this helps!
Upvotes: 1
Reputation: 5542
You could use the getSource()
and getParent()
methods to walk up the control hierarchy like this:
function linkPressListener(oEv) {
// get event source -> the link
var link = oEv.getSource();
// walk up the control hierarchy until you reach the table row (1st parent should be column, 2nd the row)
var row = link.getParent().getParent();
// get the rows index
var index = row.getIndex();
// get row context from the table
var myTable = sap.ui.getCore().byId("myTablesID");
myTable.getContextByIndex(index);
// open your dialog using the rows context
...
}
Anyways depending on the hierarchy like this seems a little fragile to me, would love to see a more elegant example.
Upvotes: 2