0

I am trying to sort the dictionary in angular JS. Below is my code

 <table ng-if='dedup==false'  class="table table-hover table-striped"  >
        <th>Name</th>
        <th class="value">Count</th>
        <tr ng-repeat="(key,value) in result.Fields[0].FieldDistributions|orderBy:value:reverse ">
            <td>{{key}}</td>
            <td> {{value|number}}</td>
        </tr>
    </table>

I want to sort the table based on the value .

What went wrong in the code. Can any one help me ?

UPDATE :

{"Fields":[{"FieldName":"Employer","FieldDistributions":{"na":"30724","UK Civil Service":"561","National Health Service":"523","Compass Group":"496","Cit Group Limited":"491","Webrecruit Ltd":"266","Med Team Primary Care Services Limited":"135","Johnson & Johnson":"124","The Allstars Group":"95","Pj Carey Contractors Limited":"88"}}]}

This is my response

Thanks,

2 Answers 2

1

For the orderBy filter, it's trying to evaluate the property on your scope for a function or string. So, it's not looking at the current value in the list; it's trying $scope.value which is probably undefined.

Rather, it's expecting a string property on each member of your list (or a function to evaluate the sort with). For example, if you had a list of people objects that you wanted to sort by name, you would use orderBy:"name":reverse.

So, you would just supply whatever property exists on your list members that you want to sort by, or implement a function to compare members of your list and pass that to orderBy.

If you're not dealing with objects, but just numeric/string values, then you can do what's suggested in this question: orderBy array item value in Angular ng-repeat.

Docs: https://docs.angularjs.org/api/ng/filter/orderBy

Sign up to request clarification or add additional context in comments.

Comments

0

not sure how your modal looks like, but can you give this a try?

<table ng-if='dedup==false'  class="table table-hover table-striped"  >
        <th>Name</th>
        <th class="value">Count</th>
        <tr ng-repeat="rowData in result.Fields[0].FieldDistributions|orderBy:value:reverse ">
            <td>{{rowData.key}}</td>
            <td> {{rowData.value|number}}</td>
        </tr>
    </table>

1 Comment

I have added my response

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.