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>
<script src="http://cdn.jsdelivr.net/underscorejs/1.6.0/underscore-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 class="warn">The pagination without any filter is really fast. Unfortunately, the filter function is slowing down the scolling. I am looking for a solution in order to speed up it. Even with 1 million elements, the scroll will be fast, but impossible to use in conjunction with filters.</li>
    <li>It's missing the scroll bar.</li>
</ul>

<div ng-app="myApp" ng-controller="MainCtrl">    
    
    Filter: <input ng-model="numberFilter"></input>    
    <button ng-click="addItem()">Add item</button>
    <button ng-click="toogleAutomaticScrolling()">
        Auto-Scroll: {{automaticScroll | uppercase}}
    </button>
        
    <table>
        <thead>
            <td>Key</td>
            <td>Value</td>
        </thead>
        <tbody scroll>
            <tr ng-repeat="d in filtered = (data | filter:numberFilter) |
                    pagination:currentPage:pageSize
                    track by d.key">
                <td>{{d.key}}</td>
                <td>{{d.value}}</td>
            </tr>
        </tbody>
    </table>    
    
    <button ng-click="showFirstPage()">First</button>
    
    <button ng-click="previousPage()">&larr;</button>
    
    <button ng-click="nextPage()">&rarr;</button>
    
    <button ng-click="showLastPage()">Last</button>
    
    <br/>
    Page {{currentPage+1}} of {{numberOfPages()}}
    <br/>
    Page Size: <input ng-model="pageSize" style="width: 4em"></input>
    <br/>
    Data Size: {{data.length}}
    <br/>
    Filtered...

CSS

body {
    font-family: Georgia;
    padding: 10px;
}

ul, table, span {
    margin: 1em 0 1em 0;
    display: block;
}

li {
    margin-left: 10px;
    line-height: 1.2em;
}

li:before {    
    content: "• ";
}

h1 {
    font-size: 2em;    
}

thead td {
    font-weight: bold;
    border-bottom: solid 2px;
}

tr td {
    padding: 2px 10px 2px 10px;
}

tbody tr td {    
    background-color: #99FF33;
}

tbody {
    overflow-y:scroll;
}

.warn {
    color: red;
}
}

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) {
        $element.on('mousewheel', function (event) {
            if(event.deltaY > 0) {
                $scope.nextPage();
            }
            else {
                $scope.previousPage();              
            }            
            $scope.$apply($element);
            event.preventDefault();
        });
    };
});

app.controller('MainCtrl', function ($scope) {
    
    $scope.automaticScroll = 'on';
    $scope.currentPage = 0;
    $scope.pageSize = 10;
    
    $scope.$watch('numberFilter', function() {
       $scope.showFirstPage();
    });
    
    $scope.$watch('pageSize', function() {
       $scope.showFirstPage();
    });
    
    $scope.$watch('data.length', function() {
        if($scope.automaticScroll == 'on') {            
            $scope.currentPage = $scope.numberOfPages()-1;
        }
    });
    
    //fake data
    var count = 100000;
    var data = [];
    for(var i=0; i<count; i++) {
        data[i] = {key: i+1, value: 'value-' + i+1};
    }
    $scope.data = data;

    $scope.numberOfPages = function () {
        return Math.ceil($scope.filtered.length / $scope.pageSize);
    };
    
    $scope.showFirstPage = function() {
        $scope.automaticScroll = 'off';
        $scope.currentPage = 0;
    };
    
    $scope.previousPage = function() {
        if($scope.currentPage > 0) {
            $scope.automaticScroll = 'off';
            $scope.currentPage = $scope.currentPage - 1;
        }
    };
        
    $scope.nextPage = function() {
        if($scope.currentPage < $scope.numberOfPages()-1) {
            $scope.automaticScroll = 'off';
            $scope.currentPage = $scope.currentPage + 1
        }
    };
    
    $scope.showLastPage = function() {
        $scope.automaticScroll = 'off';
        $scope.currentPage =...