Skip to content

Instantly share code, notes, and snippets.

View cschuff's full-sized avatar

Christian Schuff cschuff

  • Christian Schuff IT-Consulting
  • Mannheim, Germany
View GitHub Profile
@cschuff
cschuff / sap.ui.model.Sorter: Custom Sort Comparator
Last active January 28, 2017 12:36
A custom comparator that converts strings to number and compares them. Demonstrates usage in sap.ui.model.Sorter.
// String to Number Comparator
var oSorter = new sap.ui.model.Sorter("path");
oSorter.fnCompare = function (a, b) {
var valA = parseInt(a, 10);
var valB = parseInt(b, 10);
if (isNaN(valA)) return 1;
if (isNaN(valB)) return -1;
if (isNaN(valA) && isNaN(valB)) return 0;
@cschuff
cschuff / DataType.js
Last active May 30, 2019 09:05
Valid SAPUI5 property types
// found in https://github.com/SAP/openui5/blob/master/src/sap.ui.core/src/sap/ui/base/DataType.js
"any"
"boolean"
"int"
"float"
"string"
"object"
"function"
// arrays like this
@cschuff
cschuff / gist:275f4b66c155e71ab31a6df404dcfc7a
Last active February 6, 2017 14:57
ODataModel Obstacles
// always use createKey since for getData/getProperty
// "/EntitySet(Prop1='VAL-1',Prop2='VAL-2')" !== "/EntitySet(Prop2='VAL-2',Prop1='VAL-1')"
// Be aware that createKey needs ODataModel metadata
oModel.metadataLoaded().then(function () {
var sKey = oModel.createKey("/EntitySet", {
Prop1: "VAL-1",
Prop2: "VAL-2"
});
});
@cschuff
cschuff / MangedObjectConstructor
Last active February 7, 2017 08:47
Aggregation types not inherited from sap.ui.base.ManagedObject
constructor: function (sId, mSettings) {
// https://github.com/SAP/openui5/blob/master/src/sap.ui.core/src/sap/ui/base/ManagedObject.js#create
var oMyAggregation;
if ((sId && sId.myAggregation) || (mSettings && mSettings.myAggregation)) {
// delete from settings so that applySettings will not pick it up
if (sId && sId.myAggregation) {
oMyAggregation = sId.myAggregation;
delete sId.myAggregation;
}
if (mSettings && mSettings.myAggregation) {
@cschuff
cschuff / AssignmentShortcuts.js
Last active February 24, 2017 16:22
Assignment Shortcuts
// boolean defaulting to true
bValue = (bValue !== false);
bValue = bValue === undefined ? this.getValue() : bValue;
sValue = sValue || "default";
var FnConstructor = jQuery.sap.getObject(sType);
@cschuff
cschuff / RoutePatternMatched-Auto-Attach
Created February 8, 2017 08:36
Auto-attach to patternMatched event on correct sap.ui.core.routing.Route
////////////////////////////////
// Controller Lifecycle
onInit: function () {
this.getRouter().attachRoutePatternMatched(this.onAnyRoutePatternMatched, this);
},
onExit: function () {
this.getRouter().detachRoutePatternMatched(this.onAnyRoutePatternMatched, this);
this.getRouter().getRoute(this.routeName).detachPatternMatched(this.onRoutePatternMatched, this);
@cschuff
cschuff / JSDocDemo.js
Last active October 9, 2022 13:55
How to document a SAPUI5 class with regular JSDoc
/**
* @namespace
* @name ui5experts.toolbox
* @public
*/
sap.ui.define([
"sap/ui/base/ManagedObject"
], function (
ManagedObject) {
@cschuff
cschuff / findAggregatedObjects.js
Created February 22, 2017 10:33
Find an aggregated SAPUI5 object
// https://sapui5.hana.ondemand.com/#docs/api/symbols/sap.ui.base.ManagedObject.html#findAggregatedObjects
var aResults = oObject.findAggregatedObjects(true, function(o) { return o.getId() === "TEST"; });
@cschuff
cschuff / SuspendResumeBindings.js
Last active February 22, 2017 13:13
How to suspend and resume a Binding in SAPUI5 without having resume refresh it if it has pending changes from the suspended period. This can be particularly helpful if your UI already reflects the changes and you want to prevent additional rerenderings (e.g. after drag and drop operations).
var oBinding = this.byId("Control").getBinding("items");
oBinding.suspend();
// ...
oBinding.bPendingRefresh = false;
oBinding.resume();