Table: How to save the clicked row data into a variable for later binding
-
Roman MoraruHas successfully completed the online course Basics (100)2 years ago #34235
Hello,
Let*s say i do have a table with two columns, name + description x 4 rows of information.
How do i save the clicked row into a variable so it can later on be used as a binding for some controls?
Attempt: Create a struct with two parameters name, description => create a global variable (data), with this struct as a data type => via UI Actions save the selectedItem to the data variable => bind the data variable to the controls.
Issues: the selectedItem doesn’t get saved to the data variable; when binding the data to the controls it can’t be specified what parameter i want to use.
Vitali KurdasovHas successfully completed the online course Intermediate (200)Has successfully completed the online course Basics (100)Has successfully completed the online course Advanced (310)Has successfully completed the Intermediate Certification2 years ago #34237::Hi Roman,
you can use the client-side BusinessObject SF_Ui5BindingHelper with the function getSelectedListItem to extract your clicked tablerow. In the output mapping you can map the selectedItem to your global variable.
Please note to use the Table itemPress event instead of the ColumnListItem press event.
Armin WinklerHas successfully completed the online course IntroductionHas successfully completed the online course Intermediate (200)Has successfully completed the online course Advanced (300)Has successfully completed the online course Basics (100)Armin WinklerHas successfully completed the online course IntroductionHas successfully completed the online course Intermediate (200)Has successfully completed the online course Advanced (300)Has successfully completed the online course Basics (100)2 years ago #34330::Hi Roman,
you could have made it work using the ColumnListItem’s press event as well. In that case you needed to use the function getSelectedSourceItem of the business object SF_Ui5BindingHelper instead as the press event does not provide any parameter called ‘listItem’ while the itemPress event of the Table does. Please compare the description of the two events on the API Reference of OpenUI5:
https://sapui5.hana.ondemand.com/1.71.47/#/api/sap.m.ListItemBase/events/press vs. https://sapui5.hana.ondemand.com/1.71.47/#/api/sap.m.ListBase/events/itemPress
Concerning your question: You don’t necessarily have to use a struct with the fields if you rely purely on scripting. However, if you want to use the data source for binding your data to the UI and also want to do field mappings later on you are required to use a proper data type (i.e. struct), yes.
Kind regards,
Armin
You must be logged in to reply to this topic.