From 45a0df3920c9f126e405c2c7fd717a7c4a32b0e7 Mon Sep 17 00:00:00 2001 From: Mitchell Barry Date: Sat, 17 Dec 2016 09:06:52 -0600 Subject: [PATCH] [FEATURE] Model properties are sorted alphabetically --- control/lib/PopoverHelper.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/control/lib/PopoverHelper.js b/control/lib/PopoverHelper.js index 7f2b42f..4a75f2c 100644 --- a/control/lib/PopoverHelper.js +++ b/control/lib/PopoverHelper.js @@ -632,7 +632,6 @@ sap.ui.define([ _loadPropertiesAtDepth: function () { var sFragmentId = this._getId('FragmentId'); var sPropertyListId = this._getId('PropertyListId'); - var sPropertyPageId = this._getId('PropertyPageId'); var oPropertyList = Fragment.byId(sFragmentId, sPropertyListId); var sModelName = this.getCurrentModelName(); @@ -641,7 +640,8 @@ sap.ui.define([ var oModelData = this._getDataFromModel(sModelName); var aProperties = this._getControlArray(oModelData); - var oPropertiesPage = Fragment.byId(sFragmentId, sPropertyPageId); + aProperties.sort(this._sortPropertyListAlphabetically); + oPropertyList.destroyItems(); for (var i = 0; i < aProperties.length; i++) { @@ -651,6 +651,29 @@ sap.ui.define([ return this; }, + /** + * Sort Property List (Alphabetically) + * @function + * + * Sorter function to place items in property list in order. + * Uses sap.m.InputListItem.getLabel() to sort. + * + * @param {sap.m.InputListItem} a - First item in sort function + * @param {sap.m.InputListItem} b - Second item in sort function + * @returns {int} iPosition - JavaScript sort function return value + */ + _sortPropertyListAlphabetically: function (a, b) { + var sALabel = a.getLabel().toLowerCase(); + var sBLabel = b.getLabel().toLowerCase(); + if (sALabel < sBLabel) { + return -1; + } + if (sALabel > sBLabel) { + return 1; + } + return 0; + }, + /** * Get Data from Model *