Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8975

Re: Add row to UI5 table from other table

$
0
0

Hi Saumya,

here is a very basic example.

Regards, Frank

 

var result = new sap.ui.model.json.JSONModel();
sap.ui.getCore().setModel(result);
oJsonData = {  Category_Sales_for_1997 : [   { CategoryName : "Beverages", CategorySales : "11.11"},   { CategoryName : "Something", CategorySales : "33.33"},   { CategoryName : "Confections", CategorySales : "22.22"}  ] 
};
result.setData(oJsonData);
// Create the column templates
var nameColumnTemplate = new sap.ui.commons.TextField({
 value: "{CategoryName}"
});
var salesColumnTemplate = new sap.ui.commons.TextField({
 value: "{CategorySales}"
});
var oButton = new sap.ui.commons.Button({
 text: "Add a Row",
 press: function(){  var oModel = sap.ui.getCore().getModel();  var oData = oModel.getData();  oData.Category_Sales_for_1997.push({   CategoryName : "New Row", CategorySales : "12.34"  });  oModel.updateBindings();
 }
})
var oTable = new sap.ui.table.Table({ // create Table UI 
 extension : [oButton],
 columns : [   {label: "Name", template: nameColumnTemplate  },     {label: "Sales", template: salesColumnTemplate }
 ]
});
oTable.setModel(result); // bind JSON model to Table        
oTable.bindRows({path: "/Category_Sales_for_1997"} ); // bind the table rows to an array
oTable.placeAt("content"); // place Table onto UI

Viewing all articles
Browse latest Browse all 8975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>