I am relatively new to AngularJs and I came across a problem when using OrderBy: in regards to sorting objects, so I borrowed a custom filter to sort objects but I am not understanding what the correct syntax to use this Filter appropriately as it wont sort by the Key in the object I want it to:
js:
<tbody ng-repeat="(field, profile) in currentSample.dsProfile | orderByObject:'profile[display-name]' track by $index">
<tr ng-style="$index % 2 === 0 && {'background-color': '#ffffff'} ||
$index % 2 === 1 && {'background-color': '#f9f9f9'}">
<td style="width: 19%; margin: 2px; padding: 0px;"
ng-style="profile['shown-in-details'] == true && {'background-color': 'gold'} ||
profile['shown-in-details'] == false && {'background-color': 'transparent'}">
<span class="btn-property"
ng-click="showInGenericDetails(currentSample, field)"
uib-tooltip="{{field}}"
tooltip-placement="right">
<b>{{profile["display-name"]}}</b>
</span>
Filter:
app.filter('orderByObject', function() {
return function(items, field, reverse) {
var filtered = [];
angular.forEach(items, function(item) {
filtered.push(item);
});
filtered.sort(function (a, b) {
return (a[field] > b[field] ? 1 : -1);
});
if(reverse) filtered.reverse();
return filtered;
};
});
without filter
<table id="data-sources-table" class="table drag-drop">
<tbody ng-repeat="(field, profile) in currentSchema.sProfile | orderBy:PROPERTY track by $index">
<tr ng-style="$index %2 === 0 && {'background-color': '#ffffff'} ||
$index %2 === 1 && {'background-color': '#f9f9f9'}">
<td style="width: 180px">
<span class="btn-property">
<b>{{field}}</b>

fielduse name of field(property) only[]in any of the property names