I have tabular data that I'm returning from the server in the form of an array of arrays for the data, and an array of keys associated with that data. Then, I want to sort by a particular key. Now, I know I can pre-process the data and zip together an array of objects, but say I don't want to do that. Is there an easy, built-in way to do this?
Some code that doesn't actually sort but does display the data. CodePen.
JS:
var app = angular.module('helloworld', []);
app.controller('TestController', function() {
this.headers = ['foo', 'bar'];
this.data = [
[ 'lol', 'wut' ],
[ '123', 'abc' ]
];
this.predicate = '';
});
HTML:
<table ng-app="helloworld" ng-controller="TestController as test">
<thead>
<tr>
<th ng-repeat="heading in test.headers" ng-click="test.predicate = heading">{{ heading }}</th>
</tr>
</thead>
<tbody>
<tr>
<td>Predicate:</td>
<td>{{ test.predicate }}</td>
</tr>
<tr ng-repeat="row in test.data | orderBy: test.predicate">
<td ng-repeat="column in row">{{ column }}</td>
</tr>
</tbody>
</table>