Using ui-grid constants to disable scrollbars
Asked Answered
S

3

28

With the latest version of ui-grid (v3.0.0-rc.16) it is possible to turn the horizontal and vertical scrollbar off seperately. I got this working by exchanging

$scope.gridOptions.enableScrollbars = false;

with

$scope.gridOptions.enableHorizontalScrollbar = 0;
$scope.gridOptions.enableVerticalScrollbar = 0;

In the sources of ui-grid there are three Constants defined for the scrollbars:

scrollbars: {
  NEVER: 0,
  ALWAYS: 1,
  WHEN_NEEDED: 2
}

Facing the fact that ui-grid is still unstable and changed very often, i would feel more comfortable using those constants instead of the specific values. But how can i access them ?

Plunker: http://plnkr.co/edit/h0ewAZK616rKCH3T62te

Saltern answered 14/11, 2014 at 19:50 Comment(0)
S
52

Got my answer on github:

All I needed to do was to pass uiGridConstants to my controller like this:

angular.module('myApp').controller('myCtrl',function($scope,uiGridConstants) {
    ...

    $scope.gridOptions.enableHorizontalScrollbar = uiGridConstants.scrollbars.NEVER;

    ...
})
Saltern answered 16/11, 2014 at 21:47 Comment(4)
Where do you find all the options available for uiGridConstants?Erna
I console.log'd it: is it just avg, count, max, min & sum? I feel like stddev should be in thereErna
The most reliable way to get the information you need concerning ui-grid is to read the source code and to ask the developers on git hub. :)Saltern
Problem is this doesn't disable bind-scroll-vertical and ui-grid continues to swallow some scroll events.Reconstitute
I
15

With John Papa style:

ExampleController.$inject = ['$scope', 'uiGridConstants'];
function ExampleController($scope, uiGridConstants) {
    var vm = this;

    vm.gridOptions = {
        enableHorizontalScrollbar : uiGridConstants.scrollbars.NEVER,
        enableVerticalScrollbar   : uiGridConstants.scrollbars.NEVER
    };
}
Iiette answered 12/11, 2015 at 16:16 Comment(1)
This hides the scrollbars but does not stop uiGrid from interfering with scroll events.Reconstitute
G
12

A workaround for this (since WHEN_NEEDED is currently disabled) is to set enableHorizontalScrollbar: 0 on your gridOptions and then in your stylesheet have the following:

.ui-grid .ui-grid-render-container-body .ui-grid-viewport {
  overflow-x: auto !important;
}

Now the horizontal scroll bar only displays when needed.

Groat answered 7/3, 2016 at 15:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.