cancel
Showing results for 
Search instead for 
Did you mean: 

oModel.push is not a function

former_member593030
Participant
0 Kudos
1,358

Hello All,

I am currently facing one issue, Can you please help me here?

I have Created one Dynamic table on click of Button,

First record is not Problem, But when I wamt to Push my Second record it is giving this error.

oModel.push is not a function,

My Code is Here

onChildAdd1:function(){
	
	        // Get Value from Screen
            var oBSValue = this.getView().byId("BSValue").getValue();
	    var oGRO = this.getView().byId("GROValue").getValue();
			
			
			
    
    var check1 = this.getView().byId("Button").getText();
    
    		 if (check1 === "Add More"){
             this.getView().byId("Button").setText("Add More Item");  
            
    var itemRow = {"gcn":[{BSValId: oBSValue, GROValId: oGRO}]};
    
    var oTable = new sap.ui.table.Table({
    id: "table1",
	title: "Reasoncode and Ratetypes",
	visibleRowCount: 7,
	firstVisibleRow: 3,
	selectionMode: sap.ui.table.SelectionMode.Single
});  


//Define the columns and the control templates to be used
oTable.addColumn( new sap.ui.table.Column({
	label: new sap.ui.commons.Label({text: "BSValue"}),
	template: new sap.ui.commons.TextView().bindProperty("text", {path: "BSValId"}),
	width: "400px"
}));
    
oTable.addColumn( new sap.ui.table.Column({
	label: new sap.ui.commons.Label({text: "GROValue"}),
	template: new sap.ui.commons.TextView().bindProperty("text", {path: "GROValId"}),
	width: "400px"
}));


var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(itemRow);
oTable.setModel(oModel);
oTable.bindRows("/gcn"); 
oTable.placeAt("__xmlview0--jobinfo1-Collapsed--packItem");


    		 }
    		 
    		else {
//  var oModel = new sap.ui.model.json.JSONModel();
// oModel.setData(itemRow);
var oTable = sap.ui.getCore().byId("table1");
var oModel = oTable.getModel().getProperty("/");
var itemRow = {"gcn":[{BSValId: oBSValue, GROValId: oGRO}]};
oModel.push("itemRow");
oTable.getModel().setProperty("/", oModel);

    		 }




	      
	      
}

Regards,

Sujoy

View Entire Topic
Fabrice
Active Participant
0 Kudos

Hi,

i think it is because in the "else", oModel is an object not an array.

var oModel = oTable.getModel().getProperty("/");

try,

var oModel = oTable.getModel().getProperty("/gcn");
var itemRow ={BSValId: oBSValue, GROValId: oGRO};
oModel.push("itemRow");

Regards,

Fabrice