从ui-grid列标题中删除排序菜单

Mic*_*ael 27 angularjs angular-ui-grid

我创建了有三列的ui-grid,默认情况下,列标题有一个'v'形图标(在图像中用红色圆圈标记):

在此输入图像描述

这里代码和plunker:

var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.expandable', 'ui.grid.selection', 'ui.grid.pinning']);


app.controller('ThirdCtrl', ['$scope', '$http', '$log', function ($scope, $http, $log) {
      $scope.gridOptions = {
        expandableRowTemplate: 'expandableRowTemplate.html',
        expandableRowHeight: 150,
        onRegisterApi: function (gridApi) {
            gridApi.expandable.on.rowExpandedStateChanged($scope, function (row) {
                if (row.isExpanded) {
                  row.entity.subGridOptions = {
                    columnDefs: [
                    { name: 'name'},
                    { name: 'gender'},
                    { name: 'company'}
                  ]};

                  $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json')
                    .success(function(data) {
                      row.entity.subGridOptions.data = data;
                    });
                }
            });
        }
      }

      $scope.gridOptions.columnDefs = [
        { name: 'id', pinnedLeft:true },
        { name: 'name'},
        { name: 'age'},
        { name: 'address.city'}
      ];

      $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
        .success(function(data) {
          $scope.gridOptions.data = data;
        });
    }]);
Run Code Online (Sandbox Code Playgroud)
.grid {
  width: 100%;
  height: 400px;
}
Run Code Online (Sandbox Code Playgroud)
<!doctype html>
<html ng-app="app">
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-touch.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/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="ThirdCtrl">
   <div ui-grid="gridOptions" ui-grid-expandable class="grid"></div>
</div>


    <script src="app.js"></script>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

在我在项目中创建的网格上方的图像中.

我的问题是如何删除红色圆圈标题行中的"v"符号?

Chr*_*ris 57

你想要的是:

$scope.gridOptions = {
    enableColumnMenus: false
    ...
}
Run Code Online (Sandbox Code Playgroud)

  • 我不知道我会说'这不是正确答案'.OP询问如何从所有标题中删除菜单下拉菜单,这个答案对于该问题是正确的.另一个答案提供了有关粒度的其他信息,但这并没有使这个答案错误. (8认同)

小智 30

如果要从所有列中删除它,请按照Chris的建议执行以下操作:

    $scope.gridOptions = {
        enableColumnMenus: false
        ...
    }
Run Code Online (Sandbox Code Playgroud)

但是,如果要从一个或多个但不是所有列中删除它,则需要它

 $scope.gridOptions = {
    columnDefs: [
        {                    
            enableColumnMenu: false,
    ...
}
Run Code Online (Sandbox Code Playgroud)

请注意,enableColumnMenus的默认值为true.


era*_*zap 8

您可以禁用排序

    $scope.gridOptions = {
           enableSorting: false,
           .. 
    }
Run Code Online (Sandbox Code Playgroud)