AngularJS virtual list directive
How do I make an angularjs virtual list directive?
What is a angularjs virtual list directive? How do you make a angularjs virtual list directive? This script and codes were developed by Two Fucking Developers on 14 October 2022, Friday.
AngularJS virtual list directive - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>AngularJS virtual list directive</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div ng-app="virtualListApp"> <div ng-controller="MainCtrl as controller" class="row"> <div class="col-lg-6 col-md-6 col-sm-6"> <ui-virtual-list ui-data-provider="controller.dataProvider" ui-on-select="controller.onSelect(option)" ng-model="controller.selectedOption"></ui-virtual-list> </div> <div class="col-lg-6 col-md-6 col-sm-6"> <div class="selectedOption"> {{controller.selectedOption | json}} </div> </div> </div>
</div>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script> <script src="js/index.js"></script>
</body>
</html>
AngularJS virtual list directive - Script Codes CSS Codes
.row { margin: 0 !important;
}
.selectedOption { width: 300px; display: inline-block;
}
ui-virtual-list { width: 200px; max-height: 200px; overflow-y: auto; display: block;
}
ui-virtual-list .canvas { background-color: #eee; position: relative;
}
ui-virtual-list div.renderer { display: block; width: 100%; cursor: pointer; position: absolute; height: 30px; line-height: 30px;
}
ui-virtual-list div.renderer span { margin-left: 10px;
}
ui-virtual-list div.renderer.selected { background-color: #ccc;
}
ui-virtual-list div.renderer:hover { background-color: #666; color: white;
}
AngularJS virtual list directive - Script Codes JS Codes
'use strict';
/** * @ngdoc overview * @name virtualListApp * @description * # virtualListApp * * Main module of the application. */
angular.module('virtualListApp', []) .controller('MainCtrl', function () { var dp = []; for (var i=0; i<1000000; i++) { dp.push({ index: i, label: "label " + i, value: "value " + i }); } this.dataProvider = dp; this.selectedOption = null; this.onSelect = function(option) { console.log(option); }; }) .directive('uiVirtualList', [function () { return { restrict: 'E', require: "ngModel", template: '<div class="canvas" ng-style="canvasHeight">\ <div class="renderer"\ ng-repeat="item in visibleProvider"\ ng-click="onClickOption(item)"\ ng-style="item.styles"\ ng-class="{selected:\ (currentOption.value == item.value)}">\ <span>{{item.label}}</span>\ </div>\
</div>', scope: { uiDataProvider: '=', uiOnSelect: '&' }, link: function (scope, elem, attrs, ngModelCtrl) { var rowHeight = 30; scope.height = 200; scope.scrollTop = 0; scope.visibleProvider = []; scope.cellsPerPage = 0; scope.numberOfCells = 0; scope.canvasHeight = {}; // Init scope.init = function () { elem[0].addEventListener('scroll', scope.onScroll); scope.cellsPerPage = Math.round(scope.height / rowHeight); scope.numberOfCells = 3 * scope.cellsPerPage; scope.canvasHeight = { height: scope.uiDataProvider.length * rowHeight + 'px' }; scope.updateDisplayList(); }; scope.updateDisplayList = function () { var firstCell = Math.max(Math.floor(scope.scrollTop / rowHeight) - scope.cellsPerPage, 0); var cellsToCreate = Math.min(firstCell + scope.numberOfCells, scope.numberOfCells); scope.visibleProvider = scope.uiDataProvider.slice(firstCell, firstCell + cellsToCreate); for (var i = 0; i < scope.visibleProvider.length; i++) { scope.visibleProvider[i].styles = { 'top': ((firstCell + i) * rowHeight) + "px" } } }; scope.onScroll = function (evt) { scope.scrollTop = elem.prop('scrollTop'); scope.updateDisplayList(); scope.$apply(); }; scope.onClickOption = function (option) { ngModelCtrl.$setViewValue(option); scope.currentOption = option; scope.uiOnSelect({"option": option}); }; scope.init(); } }; } ]);
Developer | Two Fucking Developers |
Username | 2fdevs |
Uploaded | October 14, 2022 |
Rating | 3.5 |
Size | 2,922 Kb |
Views | 34,408 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Videogular - Simplest Example | 2,280 Kb |
Videogular - Creating a Custom Plugin | 2,893 Kb |
V0.7.2 Videogular - Controls Plugin | 2,424 Kb |
Videogular - Customizing Controls Plugin | 2,390 Kb |
Videogular - Buffering Plugin | 2,445 Kb |
Videogular - Youtube Plugin | 2,493 Kb |
Videogular - Poster Plugin | 2,504 Kb |
Videogular - Creating a Simple Playlist | 3,078 Kb |
Videogular - Using the API in your controller | 2,963 Kb |
Videogular - Overlay Play Plugin | 2,432 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Pure CSS read more toggle | Idered | 2,344 Kb |
The Walking Raymarcher | Xorxor_hu | 7,934 Kb |
Wrap_Test | Mscfourn | 7,503 Kb |
Product item | Mymahesh11 | 2,256 Kb |
Scoreboard.js basic usage | Tbleckert | 1,733 Kb |
Use the Twitchtv JSON API | Roksanaop | 3,561 Kb |
SVG Basics | HipsterBrown | 1,852 Kb |
Mondrian | Chrisarmstrong | 2,787 Kb |
Michelle, submit your photography to Unsplash. | Zaneriley | 3,368 Kb |
V.35 The Monolith Update - Hero Release Notes | Jordan | 12,045 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!