I have the following Object that I am ngRepeating over, that I want to sort by 'pricing.total'.
"data":{
"12654fcd":{
"sequenceNumber":"12654fcd",
"directionInd":"OneWay",
"journey":[ ],
"pricing":{
"total":"1200.79"
},
"breakdown":{ },
"validatingCarrier":"DL"
},
"1eb562ab":{
"sequenceNumber":"1eb562ab",
"directionInd":"OneWay",
"journey":[ ],
"pricing":{
"total":"1400.80"
},
"breakdown":{ },
"validatingCarrier":"DL"
},
}
And here is the Output:
<div class="row" data-ng-repeat="itinerary in results.data.data | orderBy:'pricing.total'">
My repeat is working fine, however I am trying to sort the output by pricing.total without any success.
How would I go about doing that? Is it even possible to achieve sort on a sub-value?
Cheers,
orderBy - filter in module ng
Orders a specified array by the expression predicate. It is ordered alphabetically for strings and numerically for numbers. Note: if you notice numbers are not being sorted as expected, make sure they are actually being saved as numbers and not strings.
Order by works for arrays only. Yours is not array, its object.
Change your data structure to
"data":[
{
"sequenceNumber":"12654fcd",
"directionInd":"OneWay",
"journey":[ ],
"pricing":{
"total":"1200.79"
},
"breakdown":{ },
"validatingCarrier":"DL"
},
{
"sequenceNumber":"1eb562ab",
"directionInd":"OneWay",
"journey":[ ],
"pricing":{
"total":"1400.80"
},
"breakdown":{ },
"validatingCarrier":"DL"
},
]