如何在ui-grid angularjs中启用水平滚动条

时间:2015-12-15 10:17:13

标签: angularjs angular-ui-grid

我正在使用angularjs ui-grid,但我没有在我的网格上获得水平滚动条,并且所有列标题都混合在一起,因为网格中没有滚动条。 如何启用水平滚动条?

2 个答案:

答案 0 :(得分:1)

如果要始终显示水平滚动条,请在滚动条选项中将enableHorizontalScrollbar设置为uiGridConstants.scrollbars.ALWAYS,如果只想在需要时显示它,请将其设置为uiGridConstants.scrollbars.WHEN_NEEDED。 / p>

var app = angular.module('app', ['ngTouch', 'ui.grid'])

  .controller('MainCtrl', ['$scope', 'uiGridConstants', function($scope, uiGridConstants) {

    $scope.yourGridOptions = {
      enableHorizontalScrollbar: uiGridConstants.scrollbars.WHEN_NEEDED, // Here!
      enableVerticalScrollbar: uiGridConstants.scrollbars.WHEN_NEEDED,
      columnDefs: [{
        name: 'col1',
        width:150
      }, {
        name: 'col2',
        width:150
      }, {
        name: 'col3',
        width:150
      }, {
        name: 'col4',
        width:150
      }],
      data: [{
        "col1": "aa",
        "col2": "bb",
        "col3": "cc",
        "col4": "dd"
      }, {
        "col1": "aa",
        "col2": "bb",
        "col3": "cc",
        "col4": "dd"
      }, {
        "col1": "aa",
        "col2": "bb",
        "col3": "cc",
        "col4": "dd"
      }]
    };
  }]);
.grid {
  width: 200px;
  height: 250px;
}
<!doctype html>
<html ng-app="app">
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.7.2/angular.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.7.2/angular-touch.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.7.2/angular-animate.js"></script>
        <script src="http://ui-grid.info/docs/grunt-scripts/csv.js"></script>
        <script src="http://ui-grid.info/docs/grunt-scripts/pdfmake.js"></script>
        <script src="http://ui-grid.info/docs/grunt-scripts/vfs_fonts.js"></script>
        <script src="http://ui-grid.info/release/ui-grid.js"></script>
        <link rel="stylesheet" href="http://ui-grid.info/release/ui-grid.css" type="text/css">
        <link rel="stylesheet" href="main.css" type="text/css">
    </head>
    <body>

      <div ng-controller="MainCtrl">
        <div id="grid1" ui-grid="yourGridOptions" class="grid"></div>
      </div>


    </body>
</html>

答案 1 :(得分:0)

设置enableHorizo​​ntalScrollbar:0

欲了解更多信息,请访问以下链接。

https://github.com/angular-ui/ui-grid/issues/2734