Skip to content

Instantly share code, notes, and snippets.

@dennisseah
Last active October 18, 2016 07:34
Show Gist options
  • Save dennisseah/49d7d3e4e8370b735c70 to your computer and use it in GitHub Desktop.
Save dennisseah/49d7d3e4e8370b735c70 to your computer and use it in GitHub Desktop.
SAPUI5: Delete items in sap.m.Table
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-libs="sap.m"
data-sap-ui-theme="sap_bluecrystal"
type="text/javascript">
</script>
<script>
$(function() {
var oModel = new sap.ui.model.json.JSONModel([
{ fname: "Joe", lname: "Doe" },
{ fname: "Mary", lname: "Ann" }
]);
var oTable = new sap.m.Table({
mode: sap.m.ListMode.Delete,
columns: [
new sap.m.Column({ header: new sap.m.Label({text: "First Name"})}),
new sap.m.Column({ header: new sap.m.Label({text: "Last Name"})}),
],
items: {
path: "/",
template: new sap.m.ColumnListItem({
cells: [
new sap.m.Text({ text: "{fname}" }),
new sap.m.Text({ text: "{lname}" }),
]
})
},
"delete": function(e) {
var path = e.getParameter('listItem').getBindingContext().getPath();
var idx = parseInt(path.substring(path.lastIndexOf('/') +1));
var m = this.getModel();
var d = m.getData();
d.splice(idx, 1);
m.setData(d);
}
});
oTable.setModel(oModel);
oTable.placeAt('content');
});
</script>
</head>
<body class="sapUiBody">
<div id="content"></div>
</body>
</html>
@mansi-manhas
Copy link

How will u add data ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment