I have been trying to find an answer for a while and have been unable to do so. I was wondering if anyone had an idea on how to sort the following data (members
property) within ng-repeat without using a third party tool.
$scope.element = {
'sortOrder' : '[0].value' // <-- what is wrong? =[
'members': [
[
{ 'name' : 'a', 'value' : 'some' },
{ 'name' : 'b', 'value' : 'value' },
{ 'name' : 'c', 'value' : 'another' },
{ 'name' : 'd', 'value' : 'value' }
],
[
{ 'name' : 'a', 'value' : 'other' },
{ 'name' : 'b', 'value' : 'stuff' },
{ 'name' : 'c', 'value' : 'cats' },
{ 'name' : 'd', 'value' : 'reddit' }
],
[
{ 'name' : 'a', 'value' : 'internets' },
{ 'name' : 'b', 'value' : 'bigdata' },
{ 'name' : 'c', 'value' : 'winwin' },
{ 'name' : 'd', 'value' : 'himom' }
]
]
}
So, the above data is essentially representing a table. The data can't be restructured for various reasons. Right now I have the following as my markup:
<table class="table">
<thead>
<tr>
<th ng-repeat="key in element.members[0]">
<a href="#" ng-click="element.sortOrder = '[' + $index + ']' + '.value'">{{ key.name }}</a>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="subelement in element.members | orderBy : element.sortOrder">
<td ng-repeat="element in subelement" ng-include src="template(element, true)">
</td>
</tr>
</tbody>
</table>
The sortOrder
property looks like... it could be correct? I looked at other examples where people had to do this sort of thing (they were using named properties instead of indexes) and I thought I might be getting somewhere, but to no avail.
Any words of enlightenment would be appreciated. Thanks!