Angular: Empty Fiddle
http://angularjs.org/
HTML
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">
<p>List of activities:</p>
<div ng-repeat="activity in getOrderedData()">
{{activity.name}}
<input type="text" ng-model="activity.position">
</div>
</div>
JavaScript
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.model = {
activities: [
{name: "activity 1", position: 1},
{name: "activity 2", position: 2},
{name: "activity 3", position: 3},
{name: "activity 4", position: 4},
{name: "activity 5", position: 5}
]
};
$scope.getOrderedData = function(){
return $scope.model.activities.sort(compare);
};
var compare = function(a,b){
if (parseInt(a.position) < parseInt(b.position))
return -1;
if (parseInt(a.position) > parseInt(b.position))
return 1;
return 0;
};
}