1

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>

jsonenter image description here

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>
14
  • for field use name of field(property) only Commented Jul 11, 2016 at 11:10
  • so just '[display-name]' Commented Jul 11, 2016 at 11:12
  • no...there is no [] in any of the property names Commented Jul 11, 2016 at 11:14
  • angular.js:12520 Error: [$injector:unpr] Unknown provider: orderByObjectFilterProvider <- orderByObjectFilter

    Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.