cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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);

  }

});

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member182372
Active Contributor
0 Kudos

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

Former Member
0 Kudos

It does't work for me..

former_member182372
Active Contributor
0 Kudos

what itemTable's roe aggregation  is bound to?

Former Member
0 Kudos

Maksim actually i didn't get your question.

"Cannot read property 'getBinding' of undefined " this is my error message on web console.

I want to add every column items when i click the button.

is it answer for you question?

Thank you

former_member182372
Active Contributor
0 Kudos

  var oTable = this.byId("itemTable");

Former Member
0 Kudos

Add: function (oEvent) {

  var oTable = this.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);

  }

I tried this

this time this error occured "Cannot read property 'getPath' of undefined"

former_member182372
Active Contributor
0 Kudos

aaand again

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

Former Member
0 Kudos

"Uncaught TypeError: Cannot read property 'getPath' of undefined" this error again..

former_member182372
Active Contributor
0 Kudos

is rows aggregation even bound to anything? do you see ant data there in table?

Former Member
0 Kudos

No I can't see any data in the table. There just show me "no data"

former_member182372
Active Contributor
0 Kudos

so that means it is not bound to anything, you should define a binding of "rows" aggregation.