Skip to content

Instantly share code, notes, and snippets.

@dennisseah
Created August 22, 2014 19:24
Show Gist options
  • Save dennisseah/db68de85266df84ce463 to your computer and use it in GitHub Desktop.
Save dennisseah/db68de85266df84ce463 to your computer and use it in GitHub Desktop.
SAPUI5: Add Icon to title in sap.ui.commons.AccordionSection
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<style>
.iphone:before {
content: '\e092 ';
font-family: 'SAP-icons';
font-size: 11px;
margin-right: 5px;
}
.ipad:before {
content: '\e093';
font-family: 'SAP-icons';
font-size: 11px;
margin-right: 5px;
}
.laptop:before {
content: '\e027';
font-family: 'SAP-icons';
font-size: 11px;
margin-right: 5px;
}
</style>
<script id="sap-ui-bootstrap"
type="text/javascript"
data-sap-ui-libs="sap.ui.commons"
data-sap-ui-theme="sap_bluecrystal" src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"></script>
<script>
$(function() {
sap.ui.commons.AccordionSection.extend('AccordionIconSection', {
metadata: {
properties : {
iconClass: 'string'
}
},
init: function() {
this.icon = new sap.ui.core.Icon({
src: 'sap-icon://decline'
});
},
exit: function() {
this.icon.destroy();
delete this.icon;
}
})
var accordion = new sap.ui.commons.Accordion();
accordion.bindAggregation('sections', '/', new AccordionIconSection({
title: '{title}',
iconClass: '{iconClass}',
content: [
new sap.ui.commons.TextView({text: 'Test'})
]
}));
accordion.onAfterRendering = function() {
if (sap.ui.commons.Accordion.prototype.onAfterRendering) {
sap.ui.commons.Accordion.prototype.onAfterRendering.apply(this);
}
var sections = this.getSections();
for (var i = 0; i < sections.length; i++) {
var section = sections[i];
section.$().find('.sapUiAcdSectionLabel').addClass(section.getIconClass());
}
}
var model = new sap.ui.model.json.JSONModel();
model.setData([
{ title: 'iPhone', iconClass: 'iphone'},
{ title: 'iPad', iconClass: 'ipad'},
{ title: 'Laptop', iconClass: 'laptop'}
]);
accordion.setModel(model);
accordion.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