Skip to Content

Error while using addRow() method in sap.ui.table.Table

Hi Experts,

I have a requirement where i have to add rows to a Table(sap.ui.table.Table) dynamically on click of a button.

In the press event of a button i used table.AddRow() method , but it is showing me following error---

sap-ui-core.js:160 2017-08-10 17:50:47.754465 The control manages the rows aggregation. The method "addRow" cannot be used programmatically! - Element sap.ui.table.Table#tb1 I am attaching my code as well as screenshot of error message i recieved.

error-message.png

sap.ui.jsview("addrow.addRow", {


	/** Specifies the Controller belonging to this View. 
	* In the case that it is not implemented, or that "null" is returned, this View does not have a Controller.
	* @memberOf addrow.addRow
	*/ 
	getControllerName : function() {
		return "addrow.addRow";
	},


	/** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed. 
	* Since the Controller is given to this method, its event handlers can be attached right away. 
	* @memberOf addrow.addRow
	*/ 
	createContent : function(oController) {
		
var oModel = new sap.ui.model.odata.ODataModel("proxy/http/services.odata.org/V4/Northwind/Northwind.svc/");
		
		sap.ui.getCore().setModel(oModel);


		var oInput = new sap.m.Text("as",{text:"{OrderID}"});
		oInput.bindElement("/Orders(10248)/OrderID");


		
		var m = [];	
	
		 
	//	alert(oModel.getProperty("/Orders(10248)/OrderID"));
	
		var req = [];
		req.Company_Name = sap.ui.getCore().byId("as");
	
		
		
	var	tbl1 = new sap.ui.table.Table("tb1",{
			
			
			editable:true,
			rows:[
			new sap.ui.table.Row("r1",{
				
				cells:[
				       
				       new sap.m.Label("first",{text:"row1"}),
				       new sap.m.Text("fifgst",{text:"row1"})


				       
				       ],
				       
				       cells:[
						       
						       new sap.m.Label("firssdt",{text:"row2"}),
						       new sap.m.Text("firsdfest",{text:"row2"})


						       
						       ],
						       cells:[
								       
								       new sap.m.Label("firewersdgfst",{text:"row3"}),
								       new sap.m.Text("firsssgrett",{text:"row3"})


								       
								       ]
								       
						
				
				
				
			})
			
			]
			
		})


		btn1 = new sap.m.Button("btn",{
			text:"++++++++++++",
			press:function(oControlEvent){
				
				tbl1.addRow(new sap.ui.table.Row("r5",{
					
					cells:[
					       
					       new sap.m.Label("firsdfgrrer45t",{text:"row1"}),
					       new sap.m.Text("fir45st",{text:"row1"})


					       
					       ],
					       
					       cells:[
							       
							       new sap.m.Label("fi4rst",{text:"row2"}),
							       new sap.m.Text("fi45rst",{text:"row2"})


							       
							       ],
							       cells:[
									       
									       new sap.m.Label("fir45gst",{text:"row3"}),
									       new sap.m.Text("firsfgt",{text:"row3"})
									       ]}))}})
	return new sap.m.Page({
			title: "Title",
			content: [
                      oInput,btn1,tbl1


			          
			          
			          
			]
		});
	}


});
Thanks and RegardsAman Anand

error-message.png (13.2 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Aug 10, 2017 at 02:33 PM

    You are adding the fields through the JS code programmatically with the use of aggregation. To add rows, you need to use data binding.

    Use a model(json) and bind the model to the table. Create entries in the model and those many rows will appear int eh table.

    If you need to add a row, create one entry in the model and refresh the table, it will reflect a new entry.

    Check this thread: https://archive.sap.com/discussions/message/14586654#14586654

    Regards,

    Sharath

    Add comment
    10|10000 characters needed characters exceeded