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

Unable to add new row in SAP UI5 Table ???

Row.view.js

createContent : function(oController) {

var aData = [

{ID: 1, Name: "Al", Age: 32, Salary: 100000},

{ID: 2, Name: "Andy", Age: 28, Salary: 75000},

{ID: 3, Name: "Anita", Age:25, Salary: 45000},

{ID: 4, Name: "Doris", Age: 24, Salary: 35000},

{ID: 5, Name: "Doris", Age: 22, Salary: 15000}

];

var oTable2 = new sap.ui.table.Table("tableId",{

title: "Table with fixed columns Example",

visibleRowCount: 5,

firstVisibleRow: 3,

selectionMode: sap.ui.table.SelectionMode.Single,

navigationMode: sap.ui.table.NavigationMode.Paginator

});

//Define the columns and the control templates to be used

oTable2.addColumn(new sap.ui.table.Column({

label: new sap.ui.commons.Label({text: "ID"}),

template: new sap.ui.commons.TextView().bindProperty("text", "ID"),

sortProperty: "ID",

filterProperty: "ID",

width: "200px"

}));

oTable2.addColumn(new sap.ui.table.Column({

label: new sap.ui.commons.Label({text: "Name"}),

template: new sap.ui.commons.TextField().bindProperty("value", "Name"),

sortProperty: "Name",

filterProperty: "Name",

width: "200px"

}));

oTable2.addColumn(new sap.ui.table.Column({

label: new sap.ui.commons.Label({text: "Age"}),

template: new sap.ui.commons.TextField().bindProperty("value", "Age"),

sortProperty: "Age",

filterProperty: "Age",

width: "200px"

}));

oTable2.addColumn(new sap.ui.table.Column({

label: new sap.ui.commons.Label({text: "Salary"}),

template: new sap.ui.commons.TextField().bindProperty("value", "Salary"),

sortProperty: "Salary",

filterProperty: "Salary",

width: "400px"

}));

var oModel2 = new sap.ui.model.json.JSONModel();

oModel2.setData({modelData: aData});

oTable2.setModel(oModel2);

oTable2.bindRows("/modelData");

var oButton = new sap.ui.commons.Button({

text : "ADD NEW ROW",

style: sap.ui.commons.ButtonStyle.Accept,

press : function() {oController.Add()}

});

var ele=[oTable2,oButton];

return ele;

}

Row.controller.js

Add:function(){

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

var row = new sap.ui.table.Row({cells:[new sap.ui.commons.TextView(),

new sap.ui.commons.TextField(),

new sap.ui.commons.TextField(),

new sap.ui.commons.TextField()

]});

var oModel = oTable.getModel().getData().modelData;

console.log(oModel);

oModel.push({ID: 6, Name: " ", Age: 25, Salary:15000});

}

imm.png (80.3 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Sep 18, 2015 at 05:24 AM

    Hi Nagaraju,

    I built your code based on MVC pattern. Please check the sample - http://plnkr.co/edit/tXBVoSybewDjvcj7SKOq?p=preview

    Regards,

    Sai Vellanki.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 18, 2015 at 04:39 AM

    please tell me how to solve this problem

    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.