Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[SAPUI5] Get data of an Item of a List or Table

All options have in common that you first try to get the binding context from the list/table element via the event. Having the right context, you can either use the getProperty() function to get a specific property, or use the getObject() function to get all data.

onClick: function (oEvent) {
    // Option 1
    oEvent.getParameters().item.getBindingContext().getProperty("ID") 
    // Option 2
    oEvent.getParameters().item.getBindingContext().getObject().ID
    // Option 3
    oEvent.getParameter("item").getBindingContext().getObject().ID 
    // Option 4
    oEvent.getSource().getBindingContext().getObject().ID 
}

Note: When using a List, it’s oEvent.getParameters().listItem instead of oEvent.getParameters().item.

Or you could also use the sPath property from the binding context and directly get the data from the model.

onClick: function (oEvent) {
    // Option 5
    const sPath = oEvent.getSource().getBindingContext().sPath 
    // 5a
    this.getView().getModel().getProperty(sPath).ID 
    // 5b
    this.getView().getModel().getProperty(sPath + "/ID") 
}

[SAPUI5] uncheck checkbox if another one is selected

XML

<Checkbox id="Checkbox1" selected="{ path:'oModel>CB1' }" select="handleOrderSelected"></Checkbox>	
<Checkbox id="Checkbox2" selected="{ path:'oModel>CB2' }" select="handleRejectSelected"></Checkbox>

controller.js

	handleOrderSelected: function (oEvent) {
		//Wenn Checkbox1 selektiert, setze Checkbox2 auf false.
		var bSelected = oEvent.getParameter("selected");
		if (bSelected) {
			var bindingContext = oEvent.getSource().getBindingContext("oModel");
			this.oModelTemplate.setProperty("CB2", "", bindingContext, false);
		}
	},

	handleRejectSelected: function (oEvent) {
		//Wenn Checkbox2 selektiert, setze Checkbox1 auf false.
		var bSelected = oEvent.getParameter("selected");
		if (bSelected) {
			var bindingContext = oEvent.getSource().getBindingContext("oModel");
			this.oModelTemplate.setProperty("CB1", "", bindingContext, false);
		}
	}