I want to create a Highscore table.
I have an multidimensional array which I display in my script through ng-repeat in a table. My array looks like this:
[["name1","name2","name3"],[1,2,1,],[12,24,4]]
<tbody>
<tr ng-repeat="x in highscoreEntries track by $index">
<td>{{$index+1}}</td> <!--Showing the rank number-->
<td ng-repeat="y in x track by $index">{{y}}</td>
</tr>
</tbody>
[["name3","name1","name2"],[1,1,2],[4,12,24]]
Try this sort method. its working. You should change index of the value from each array.
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
var arr = [["name1","name2","name3"],[1,2,1],[12,24,4]];
$scope.highscoreEntries = [];
for(var i=0;i<arr.length;i++){
$scope.highscoreEntries.push(sortA(arr[i]));
}
function sortA(arr){
var element = arr[2]; // 2 is from index
arr.splice(2, 1); // 2 is from index
arr.splice(0, 0, element); // .splice(toindex,0,element)
return arr;
}
});
<script data-semver="1.4.9" src="https://code.angularjs.org/1.4.9/angular.js" data-require="angular.js@1.4.x"></script>
<body ng-app="plunker" ng-controller="MainCtrl">
<table>
<tbody>
<tr ng-repeat="x in highscoreEntries track by $index">
<td>{{$index+1}}</td> <!--Showing the rank number-->
<td ng-repeat="y in x track by $index">{{y}}</td>
</tr>
</tbody>
</table>
</body>