on 01-14-2021 3:37 PM
Hi,
Structure of my app:
Empty table with button at header which will open a dialog of simpleForm to fill student details and one click "Add", the input field entries has to be added in table.
Two fragments using. One is for table (imported the fragment in view) and another is for dialog (loaded the dialog fragment in controller file).
Dialog.fragment.xml:
<beginButton>
<Button text="Add" type="Emphasized" press="onDialogAddRecord"/>
</beginButton>
Home.controller.js:
sap.ui.define(["sap/ui/model/json/JSONModel", func...
onDialogAddRecord: function (oEvent) {
var Dfname = sap.ui.getCore().byId("inputFirstName").getValue();
var Dmobno = sap.ui.getCore().byId("inputMobileNo").getValue();
var oTable = sap.ui.getCore().byId("table");
var studModel = new JSONModel();
var studData = {
fname: Dfname,
mobile: Dmobno,
};
// set the data to JSON model and assigned path name
studModel.setData({"students":studData});
// binding model to table
oTable.setModel(studModel);
// closing the dialog
this.oDialog.close();
}
Table.fragment.xml:
<Table id="table" items="{/students}">
<columns>
<Column>
<Label text="Name"/>
</Column>
<Column>
<Label text="Contact Number"/>
</Column>
</columns>
<items>
<ColumnListItem >
<cells>
<Text text="{fname}"/>
<Text text="{mobile}"/>
</cells>
</ColumnListItem>
</items>
</Table>
After adding details, when i click ADD, i am getting an error as setModel is undefined. Attached the error screenshot below for your reference.
Hello,
In your definition, the students is not an array. You probably should do this :
{
Students : [{
Flame: "",
Mobile: ""
}]
}
Regards,
Joseph
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Subin,
Please avoid using sap.ui.getCore().byId() method to get the control from the view as a best pratice. The Id assigned to the view will be different at runtime.
Instead use this.getView().byId(), this will make sure you get the design time id and I think this will also resolve your issue.
Thanks
Prashil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.