cancel
Showing results for 
Search instead for 
Did you mean: 

When do I need getBindingContext or getBinding

0 Kudos

Hi all,

I wonder when I need the classes getBindingContext or getBinding in context of a sap.ui.table.Table.
In which use cases do I need this?


Many thanks

Regards

Mario


Accepted Solutions (1)

Accepted Solutions (1)

maheshpalavalli
Active Contributor

Hi Mario Mueller,

It's there in the documentation only.. If you go to the sap.ui.table.Table in api referece(UI5 SDK), search for getBinding.. That method will be inherited from ManagedObject. Clikcing on it will take you to the managedObject class.

The documentation itself is pretty self explanatory.

getBinding will give you the property & aggregation binding info done to that control

For example:

1. If you binded the "rows" aggregation to a model, then calling the oTable.getBinding("rows") will give you the binding information of the "rows" aggregation. similar we can do to all properties of the controls.

It will give you a lot other details, check: sap.ui.model.Binding sub classes.

getBindingContext will give you the binding context you applied on a control (element binding details)

If you do an element binding (context binding) for a control, then using the getBindingContext for a control will return you the context details that were applied for a control.

For example:

1. If you did the elemnt Binding for a view and request for this.getView().getBindingContext(modelName) will give you the details of the binding you have done on the control, for example path, or It will give you the data that is requested by the control when you did the element binding.

2. If you using the ui.table then the array of data you are passing to the rows (rows="{data>/products}" will result in multiple rows of the table. Internally sap ui5 apis will do a context binding for the every row that is generated. So when you use the event handler method on the item click, then you can call item.getBindingContext(), which will return you the bindingContext details for the row. you can also do item.getBindingContext().getObject() for the data.

https://ui5.sap.com/#/api/sap.ui.base.ManagedObject/methods/getBinding

If you are new to UI5, do the walkthrough section in SDK atleast 2 times which has more than enough information to get you started into UI5 🙂 Happy coding!

BR,

Mahesh

Answers (1)

Answers (1)

0 Kudos

Hi Mahesh,

thanks for the hint doing the walkthrough at least two times!!

I will do it again.

Many thanks

Best Regards

Mario

VishnuVardhan
Explorer
0 Kudos

Did completing the walkthrough twice helped you. ?