Skip to content

Instantly share code, notes, and snippets.

@dennisseah
Last active November 3, 2022 05:49
Show Gist options
  • Save dennisseah/a1c84247b1119557c319 to your computer and use it in GitHub Desktop.
Save dennisseah/a1c84247b1119557c319 to your computer and use it in GitHub Desktop.
SAPUI5: Double Tap on items in sap.m.List
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script id="sap-ui-bootstrap"
type="text/javascript"
data-sap-ui-libs="sap.m"
data-sap-ui-theme="sap_bluecrystal"
src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js">
</script>
<script>
jQuery(function() {
sap.m.StandardListItem.extend('DbClickItem', {
metadata: {
events: {
dbClick: {}
}
},
renderer: function (oRm, oControl) {
sap.m.StandardListItemRenderer.render(oRm, oControl);
},
onAfterRendering: function () {
if (sap.m.StandardListItem.prototype.onAfterRendering) {
sap.m.StandardListItem.prototype.onAfterRendering.apply(this, arguments);
}
this.$().bind('dblclick', function () {
this.fireDbClick();
}.bind(this));
}
});
var myData = {
"fruits": [
{ "item": "Apple"},
{ "item": "Orange"},
{ "item": "Banana"},
{ "item": "Pineapple"},
{ "item": "Mango"}
]
};
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(myData);
var itemTemplate = new DbClickItem({
title: "{item}"
}).attachDbClick(function (e) {
var obj = e.getSource().getBindingContext().getObject();
alert(JSON.stringify(obj));
});;
var oList1 = new sap.m.List({
mode: 'SingleSelectMaster'
});
oList1.setModel(oModel);
oList1.bindAggregation("items", "/fruits", itemTemplate);
oList1.placeAt("content");
});
</script>
</head>
<body class="sapUiBody">
<div id="content"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment