2
2
@name Tutorial: 407 Custom Scrolling
3
3
@description
4
4
5
- <div class="alert alert-info" role="alert"><strong>Note</strong> It is highly recommended that you turn this feature on alongside pinning, especially
6
- if you plan on using ui-grid on devices.</div>
7
-
8
- The custom scrolling feature takes over the default scrolling logic in order to ensure that grid scrolling works without a lag on devices.
9
- To enable, you must include the 'ui.grid.customScrolling' module and you must include the ui-grid-custom-scrolling directive on your grid element.
5
+ The custom scrolling feature allows you to provide your own scroller function to replace default element.on('scroll') function. It is particularly
6
+ helpful if you are facing issues with scrolling on devices or slow machines, because it allows you to use thirdparty scrollers.
10
7
11
8
Documentation for the custom scrolling feature is provided in the api documentation, in particular:
12
9
13
- - {@link api/ui.grid.customScrolling.constant:uiGridScrollerConstants uiGridScrollerConstants}
14
- - {@link api/ui.grid.customScrolling.service:uiGridScroller uiGridScroller}
15
- - {@link api/ui.grid.customScrolling.directive:uiGridCustomScrolling uiGridCustomScrolling}
10
+ - {@link api/ui.grid.class:GridOptions customScroller}
16
11
17
12
@example
18
13
<example module="app">
19
14
<file name="app.js">
20
- var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.pinning', 'ui.grid.customScrolling' ]);
15
+ var app = angular.module('app', ['ngTouch', 'ui.grid']);
21
16
22
17
app.controller('MainCtrl', ['$scope', '$http', '$log', function ($scope, $http, $log) {
23
- $scope.gridOptions = {};
18
+ $scope.scroll ={
19
+ top: 0,
20
+ left: 0
21
+ };
22
+
23
+ $scope.gridOptions = {
24
+ customScroller: function myScrolling(uiGridViewport, scrollHandler) {
25
+ uiGridViewport.on('scroll', function myScrollingOverride(event) {
26
+ $scope.scroll.top = uiGridViewport[0].scrollTop;
27
+ $scope.scroll.left = uiGridViewport[0].scrollLeft;
28
+
29
+ // You should always pass the event to the callback since ui-grid needs it
30
+ scrollHandler(event);
31
+ });
32
+ }
33
+ };
24
34
25
35
$scope.gridOptions.columnDefs = [
26
- { name:'id', width:50, enablePinning:false },
27
- { name:'name', width:100, pinnedLeft:true },
28
- { name:'age', width:100, pinnedRight:true },
36
+ { name:'id', width:50 },
37
+ { name:'name', width:100 },
38
+ { name:'age', width:100 },
29
39
{ name:'address.street', width:150 },
30
40
{ name:'address.city', width:150 },
31
41
{ name:'address.state', width:50 },
@@ -47,7 +57,17 @@ Documentation for the custom scrolling feature is provided in the api documentat
47
57
</file>
48
58
<file name="index.html">
49
59
<div ng-controller="MainCtrl">
50
- <div ui-grid="gridOptions" class="grid" ui-grid-pinning ui-grid-custom-scrolling></div>
60
+ <div class="row">
61
+ <label class="col-sm-2">Scroll Top: </label>
62
+ <div class="col-sm-4">
63
+ {{ scroll.top }}
64
+ </div>
65
+ <label class="col-sm-2">Scroll Left: </label>
66
+ <div class="col-sm-4">
67
+ {{ scroll.left }}
68
+ </div>
69
+ </div>
70
+ <div ui-grid="gridOptions" class="grid"></div>
51
71
</div>
52
72
</file>
53
73
<file name="main.css">
0 commit comments