In my UI5-app, I have a table where each row contains a sap.m.Switch, which is bound to the model via formatter, since the data is coming from the DB as 1/0, rather than true/false, and that, probably, breaks the default two-way data binding.
To update a data model upon the editing value of this switch, I implemented the following change-event:
onChangeSwitch: function onChangeSwitch(oEvent) {
let context = oEvent.oSource.getBindingContext();
let itemIndex = context.sPath.substr(1);
let oModel = this.getView().byId("idTablePersons").getModel();
oModel.oData[itemIndex].isPersonActive = (oEvent.mParameters.state) ? 1 : 0;
oModel.refresh();
}
It works, but I'm not sure if it is a proper way to implement such logic.
Is there a standard way to update a model after changing sap.m.Switch value?