Skip to Content
author's profile photo Former Member
Former Member

Question about table add Function with xml.view and js controller

I want to add table row in xml.view using js controller. I tried many times but i couldn't figure out.. Please help me senior Ui developers!!


xml.view

<object:ObjectPageSection title ="Item"/>

<content>

<t:Table id ="itemTable" visibleRowCount = "1" firstVisibleRow = "1">

<t:toolbar>

<Toolbar>

<ToolbarSpacer/>

<Button icon = "sap-icon://add" press = "Add" />

</Toolbar>

</t:toolbar>

<t:Column autoResizable = "true">

<Label text = "MM#"/>

<t:template><c:TextField value = "{mm}"/></t:template>

</t:Column>

<t:Column autoResizable = "true">

<Label text = "Description" />

<t:template><c:TextView text = "{des}" /></t:template>

</t:Column>

<t:Column autoResizable = "true">

<Label text = "Qty" />

<t:template><c:TextView text = "{qty}"/></t:template>

</t:Column>

<t:Column autoResizable = "true">

<Label text = "Unit" />

<t:template><c:TextView text = "{unit}"/></t:template>

</t:Column>

<t:Column autoResizable = "true">

<Label text = "@ Price" />

<t:template><c:TextView text = "{price}"/></t:template>

</t:Column>

<t:Column autoResizable = "true">

<Label text = "Net Amount" />

<t:template><c:TextView text = "{net}"/></t:template>

</t:Column>

</t:Table>

controller.js

sap.ui.controller("zhmmatest.CreatePR", {

onInit: function() {

},

Add: function (oEvent) {

var oTable = sap.ui.getCore().byId("itemTable");

var oPath = oTable.getBinding().getPath();

var oModel = oTable.getModel().getProperty(oPath);

console.log(oModel);

oModel.unshift({

mm: 6,

des: "hello",

qty: 12,

unit: 13,

price: 12,

net: 12

});

oTable.getModel().setProperty(oPath, oModel);

otable.bindRows(oPath);

}

});

output.png (5.0 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Jan 15, 2016 at 09:55 PM

    var oPath = oTable.getBinding("rows").getPath();

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.