hi experts,
I'm new to sap ui5..i just created while click add button the data store in table..i want know, how can i delete rows..help me!
its my code:
createContent : function(oController) {
var layout = new sap.ui.commons.layout.MatrixLayout('layout');
layout.setWidth('100%');
var loginPannel = new sap.ui.commons.Panel('loginPannel');
var sTitle = new sap.ui.commons.Title('sTitle');
sTitle.setText('Login Page');
loginPannel.setTitle(sTitle);
var sLayout = new sap.ui.commons.layout.MatrixLayout('sLayout');
sLayout.setWidth('50%');
var label = new sap.ui.commons.Label( { text : "First Name" } );
var text = new sap.ui.commons.TextField("firstname",{ }) ;
var label1 = new sap.ui.commons.Label({ text : "Last Name" });
var text1 = new sap.ui.commons.TextField("lastname",{ }) ;
var label2 = new sap.ui.commons.Label( { text : "Age" } );
var text2 = new sap.ui.commons.TextField("age",{ }) ;
var label3 = new sap.ui.commons.Label( { text : "Address" } );
var text3 = new sap.ui.commons.TextField("address",{ }) ;
var EmployeesCounter = 3;
var oButton = new sap.ui.commons.Button({text:"Add",
press:function(){
var fname = sap.ui.getCore().byId('firstname').getValue();
var lname = sap.ui.getCore().byId('lastname').getValue();
var age = sap.ui.getCore().byId('age').getValue();
var address = sap.ui.getCore().byId('address').getValue();
mdData.Employees.push({"firstName":fname,"lastName":lname,"age":age,"address":address,"id":EmployeesCounter++});
oModel.setData(mdData);
alert("Data added successfully");
}
});
sLayout.createRow(label, text);
sLayout.createRow(label1, text1);
sLayout.createRow(label2, text2);
sLayout.createRow(label3, text3);
sLayout.createRow(oButton);
loginPannel.addContent(sLayout);
layout.createRow(loginPannel);
layout.placeAt('content');
this.addContent(layout);
var mdData = {
Employees:[
{firstName:"Pal", lastName:"saran",age:"25",address:"Salem", id: "1"},
{firstName:"Mahesh", lastName:"babu", age:"28",address:"Hosur",id: "2"},
]
};
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(mdData);
sap.ui.getCore().setModel(oModel);
var oTable = new sap.ui.table.DataTable({
title : "Employees",
width : "100%",
visibleRowCount : 5,
selectionMode : sap.ui.table.SelectionMode.None,
editable : false
});
oTable.addColumn(new sap.ui.table.ColumnHeader({
label: new sap.ui.commons.Label({text: "S.No"}),
template: new sap.ui.commons.Label({text:"{id}"})
}));
oTable.addColumn(new sap.ui.table.ColumnHeader({
label: new sap.ui.commons.Label({text: "First Name"}),
template: new sap.ui.commons.TextField({value:"{firstName}"})
}));
oTable.addColumn(new sap.ui.table.ColumnHeader({
label: new sap.ui.commons.Label({text: "Last Name"}),
template: new sap.ui.commons.TextField({value:"{lastName}"})
}));
oTable.addColumn(new sap.ui.table.ColumnHeader({
label: new sap.ui.commons.Label({text: "Age"}),
template: new sap.ui.commons.TextField({value:"{age}"})
}));
oTable.addColumn(new sap.ui.table.ColumnHeader({
label: new sap.ui.commons.Label({text: "Address"}),
template: new sap.ui.commons.TextField({value:"{address}"})
}));
oTable.bindRows("/Employees");
oTable.placeAt("content");
}
});