cancel
Showing results for 
Search instead for 
Did you mean: 

How do I populate a table inside a fragment?

former_member595374
Participant
0 Kudos

I have this table where I have a table inside a scroll container.

<core:FragmentDefinition xmlns="sap.m" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:core="sap.ui.core" xmlns:t="sap.ui.table" xmlns:l="sap.ui.layout"
controllerName="proj.controller.Area">


<Label text="Columns" width="100%" id="label1_1541454925956"/>
<Input xmlns="sap.m" value="Value" id="columnsInput" type="Number"/>
<Label text="Rows" width="100%" id="label0_1541454900545"/>
<Input xmlns="sap.m" value="Value" id="rowsInput" type="Number"/>

<ScrollContainer id="scrollContainer" horizontal="true" vertical="true">
<Table xmlns="sap.m" id="OTable"></Table>
</ScrollContainer>
</core:FragmentDefinition>

I want to populate this table through Javascript, similar to this code here: https://answers.sap.com/questions/345848/populate-grid-table-sapui5-dynamically.html.

However, I am having trouble connecting to the Javascript and populating.

/*eslint-disable no-console, no-alert */
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/core/Fragment"
], function (Controller, Fragment) {
return Controller.extend("[proj.controller.Area", {
onInit: function () {
var table = sap.ui.xmlfragment("proj.controller.Area", this);
table.populate();
},
populate: function (oEvent) {
//add code from link
}
});
});

Is this possible? Why is my fragment not reacting to the code?

Accepted Solutions (0)

Answers (1)

Answers (1)

junwu
Active Contributor
0 Kudos
table.populate();   ======>this.populate()
former_member595374
Participant
0 Kudos

Thanks! I changed it to this.populate(). However, i'm still finding that the function isn't being called. I've even added a simple alert("hello world") inside populate just in case it was my code that wasn't working but the alert doesn't pop up. Actually, now that I look at it, even why I inspect element and search for the Javascript file, I cannot find it. It seems like my Javascript file isn't properly attached somehow?

junwu
Active Contributor
0 Kudos

is the controller loaded?