Skip to Content
-1
Jun 01, 2015 at 10:10 AM

Adding New Value to sap.m.Table(using bind aggregation)

1543 Views

Hello All,

I want to add a new value to sap.m.table via a JSON file using Bind Aggregation.

Code:

var oLbl1 = new sap.m.Label({

id : "idlabel", // sap.ui.core.ID

design : sap.m.LabelDesign.Standard, // sap.m.LabelDesign

text : "BARCODE", // string

visible : true, // boolean

textAlign : sap.ui.core.TextAlign.Begin, // sap.ui.core.TextAlign

textDirection : sap.ui.core.TextDirection.Inherit, //

width : '100%', // sap.ui.core.CSSSize

required : true, // boolean

});

var oInputBar = new sap.m.Input({

id:"idinput",

width:"100%"

});

var oModel = new sap.ui.model.json.JSONModel("Model/data.json");

var oTable = new sap.m.Table({

width:"100%"

});

oTable.addColumn(new sap.m.Column({}));

oTable.addColumn(new sap.m.Column({}));

var oTemplate = new sap.m.ColumnListItem({

type : sap.m.ListType.Active,

cells : [ new sap.m.Label({

text : "{SlNo}"

}), new sap.m.Label({

text : "{title}"

}) ]

});

oTable.setModel(oModel);

console.log(JSON.stringify(oModel.getData()))

oTable.bindAggregation("items", {

path : "/commodity",// <<<Your data path at runtime

template : oTemplate

});

var oSubmit1 = new sap.m.Button({

text : "Set",

width : "50%",

});

var oBack = new sap.m.Button({

text : "Back",

width : "50%",

});

var oUp = new sap.m.Button({

text : "PgUp",

width : "50%",

});

var oDown = new sap.m.Button({

text : "PgDn",

width : "50%",

});

oSubmit1.attachPress(function() {

var oInputBar1 = oInputBar.getValue();

var aData;

alert(oInputBar1);

var modelData = oModel.getData();

alert(JSON.stringify(modelData))

modelData.push({

"SlNo" : aData

});

// _________________DATA PUSH TO MODEL

var oModel1 = oModel.setData({

modelData : aData

}); // SET MODEL

});