Angular: CSS styling
http://angularjs.org/
by Alexandre Verri
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<script src="https://code.jquery.com/jquery-2.1.0.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.6/jquery.mousewheel.min.js"></script>
<h1>Paginated Scrolling</h1>
<ul>
<li>The intention is to do a fast pagination in large tables.</li>
<li>You can scroll the table body using mouse.</li>
<li>It's missing the scroll bar.</li>
</ul>
<div ng-app="myApp" ng-controller="MainCtrl">
Filter: <input ng-model="numberFilter"></input>
<br/>
<table>
<thead>
<td>Numbers</td>
</thead>
<tbody scroll>
<tr ng-repeat="d in filtered = (data | filter:numberFilter) |
startFrom:currentPage*pageSize |
limitTo:pageSize">
<td>{{d}}</td>
</tr>
</tbody>
</table>
Page {{currentPage+1}} of {{numberOfPages()}}
<br/>
Page Size: <input ng-model="pageSize" style="width: 4em"></input>
<br/>
Data Size: {{data.length}}
<br/>
Filtered Size: {{filtered.length}}
</div>
CSS
body {
font-family: Georgia;
}
ul, table {
margin: 1em 0 1em 0;
}
li:before {
content: "• ";
}
h1 {
font-size: 2em;
line-height: 2em;
}
thead td {
font-weight: bold;
border-bottom: solid 2px;
}
tbody tr td {
width: 50px;
background-color: #99FF33;
}
tbody {
overflow-y:scroll;
}
JavaScript
app = angular.module('myApp', []);
// The custom scroll directive. It uses the jQuery Mousewheel plugin.
app.directive("scroll", function ($window) {
return function ($scope, $element, $attrs) {
jQuery($element).on('mousewheel', function (event) {
if(event.deltaY < 0) {
if($scope.currentPage < $scope.numberOfPages()-1) {
$scope.currentPage = $scope.currentPage + 1
}
}
else {
if($scope.currentPage > 0) {
$scope.currentPage = $scope.currentPage - 1;
}
}
$scope.$apply();
event.preventDefault();
});
};
});
app.controller('MainCtrl', function ($scope) {
$scope.currentPage = 0;
$scope.pageSize = 10;
$scope.$watch('numberFilter', function() {
$scope.currentPage = 0;
});
$scope.$watch('pageSize', function() {
$scope.currentPage = 0;
});
//fake data
var count = 10000;
var data = [];
for(var i=0; i<count; i++) {
data[i] = i+1;
}
$scope.data = data;
$scope.numberOfPages = function () {
return Math.ceil($scope.filtered.length / $scope.pageSize);
};
});
// The custom filter to be used in ng-repeat.
app.filter('startFrom', function () {
return function (input, start) {
console.log('Start: ' + start);
start = +start;
return input.slice(start);
};
});