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

Re: Creating a row in a table with empty fields and saving the new data to DB after clicking save button

$
0
0

I am writing below code , data is getting into the table , but adding is not working any mistake in my code please help me

 

 

model.js:


jQuery.sap.declare("sap.ui.Default.model.MData");

 

 

sap.ui.Default.model.MMData = {};

 

 

sap.ui.Default.model.MData.getList = function() {

  var url = '/XMII/IlluminatorOData/QueryTemplate?QueryTemplate=Default/Queries/getListMDOQry';

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

  oModel.setDefaultBindingMode(sap.ui.model.BindingMode.OneTime);

  oModel.loadData(url, {

  '$format' : 'json'

  }, false);

  return oModel;

};

 

 

view.js:

 

createContent : function(oController) {

 

 

var oEmpId = new sap.ui.table.Column({label : new sap.ui.commons.Label({text : 'ID'}),

          template : new sap.ui.commons.TextField("empId",{editable:false})

  .bindProperty('value', 'EmpId').setTextAlign(sap.ui.core.TextAlign.Center )});

 

 

var oEmpName = new sap.ui.table.Column({label : new sap.ui.commons.Label({text : 'Name'}),

  template : new sap.ui.commons.TextField("nameId",{editable:true})

  .bindProperty('value', 'EmpName').setTextAlign(sap.ui.core.TextAlign.Center )});

 

 

var oEmpAge = new sap.ui.table.Column({label : new sap.ui.commons.Label({text : 'Age'}),

  template : new sap.ui.commons.TextField("ageId",{editable:true})

  .bindProperty('value', 'EmpAge').setTextAlign(sap.ui.core.TextAlign.Center )});

 

 

var oEmpSalary = new sap.ui.table.Column({label : new sap.ui.commons.Label({text : 'Salary',}),

  template : new sap.ui.commons.TextField("measureId",{editable:true})

  .bindProperty('value', 'EmpSalary').setTextAlign(sap.ui.core.TextAlign.Center )});

 

 

var oTable = new sap.ui.table.Table("MM-Table",{

  title : '',

  visibleRowCount :6 ,

  firstVisibleRow:4,

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

  navigationMode : sap.ui.table.NavigationMode.Paginator,

  columns : [oEmpId,oEmpName,oEmpAge,oEmpSalary],

  rows : {

  path : '/d/results/0/Rowset/results/0/Row/results',

  template : new sap.ui.table.Row()

  }

  });

var oButton=new sap.ui.commons.Buton("Addbtn",{text:"ADD NEW RECORD",press:function(){oController.Add()}});

var ele=[oTable,oButton];

return ele;

}

});

 

 

controller.js

 

onInit: function() {

 

 

var modelData=sap.ui.Default.model.MData.getList();

sap.ui.getCore().byId("MM-Table").setModel(modelData);

},

 

 

 

 

 

 

 

 

 

 

Add:function(oEvent){

 

  

var oTable = sap.ui.getCore().byId("MM-Table");

 

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

 

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

  

console.log(oModel);

 

var empid=oTable._getRowCount();

oModel.push({ID: empid});

  

oTable.bindRows("/modelData");

 

 

}


Viewing all articles
Browse latest Browse all 2756

Trending Articles



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