View1.view.xml
<mvc:View controllerName="real.controller.View1"
xmlns:mvc="sap.ui.core.mvc" displayBlock="true"
xmlns:f="sap.ui.layout.form"
xmlns="sap.m">
<Page id="page" title="{i18n>title}">
<content>
<Table items="{crud>/}" id="abc" selectionChange="onSelectionChange" mode="SingleSelectLeft" includeItemInSelection="true">
<columns>
<Column>
<Text text="ID"></Text>
</Column>
<Column>
<Text text="Name"></Text>
</Column>
<Column minScreenWidth="Tablet">
<Text text="City"></Text>
</Column>
</columns>
<items>
<ColumnListItem >
<cells>
<Text text="{crud>ID}"></Text>
<Input value="{crud>Name}"></Input>
<Text text="{crud>Address/City}"></Text>
</cells>
</ColumnListItem>
</items>
</Table>
<f:SimpleForm id="SimpleFormDisplay354" editable="true">
<f:content>
<Label text="ID" />
<Input value="{selectedRow>/ID}" width="20%" /> <!-- Bind to "ID" property in the "selectedRow" model -->
<Label text="Name" width="20%" />
<Input value="{selectedRow>/Name}" width="20%" /> <!-- Bind to "Name" property in the "selectedRow" model -->
<Label text="City" />
<Input value="{selectedRow>/Address/City}" width="20%" /> <!-- Bind to "City" property in the "selectedRow" model -->
</f:content>
</f:SimpleForm>
</content>
</Page>
</mvc:View>
View1.controller.js
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel"
],
/**
* @param {typeof sap.ui.core.mvc.Controller} Controller
*/
function (Controller,JSONModel) {
"use strict";
return Controller.extend("real.controller.View1", {
onInit: function () {
var data =this.getOwnerComponent().getModel();
var json = new JSONModel();
var oThis=this;
data.read("/Suppliers",{
success: function (oData){
json.setData(oData.results);
oThis.getView().byId("abc").setModel(json, "crud");
},
error: function (oData) {
},
});
},
onSelectionChange: function(oEvent) {
var oTable = oEvent.getSource(); // Get the table control
var aSelectedItems = oTable.getSelectedItems(); // Get the selected items
var oSelectedData;
if (aSelectedItems.length > 0) {
oSelectedData = aSelectedItems[0].getBindingContext("crud").getObject();
}
var oForm = this.getView().byId("SimpleFormDisplay354"); // Get the form control by its ID
oForm.setModel(new sap.ui.model.json.JSONModel(oSelectedData), "selectedRow"); // Set the selected row data as a new model for the form
}
});
})