AngularJs& ui-grid:grid忽略gridOptions

时间:2016-08-05 10:37:48

标签: javascript angularjs angular-ui-grid ui-grid

我遇到了使用ui-grid的问题来禁用gridMenu并重命名我的列。我做了一个plnkr,你可以看到:https://plnkr.co/edit/EGhvBGOJCKPzfupjCROx?p=preview

正如您在script.js中所看到的,我希望我的列名为'banana','chrom'和'position':

var app = angular.module('myApp', ['ui.grid']);
app.service('provide', ['$http', function($http) {
   return {
    getAllVariants: function () { 
        return $http.get('./varAjax.php');
     }
    };
   }]);

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

    provide.getAllVariants().success(function(data) {
        $scope.gridOptions.data = data;
        $scope.myData = data;
        console.log($scope.gridOptions);
        console.log($scope.myData);
    });

    $scope.gridOptions = {
        data: 'myData',
        enableGridMenu: false,
        showGroupPanel: true,
        enableColumnResizing: true,
        enableFiltering: true,
        showGridFooter: true,
        showColumnFooter: true,
        columnDefs: [
            { name: 'id', displayName: 'banana', width: 30 },
            { name: 'chr', displayName: 'chrom', width: 30},
            { name: 'pos_start', displayName: 'position', width: 50}
            ]
    };

}]);

数据看起来像这样:

[
 {
 "id":"1","chr":"chr1","pos_start":"11169789"
 },
 {
 "id":"2","chr":"chr1","pos_start":"11172923"
 }
]

以下是我称之为网格的方式:

<body>
    <h1>Variants</h1>
    <div ng-app="myApp" ng-controller="MainCtrl">
      <div id="grid1" ui-grid="{ data: myData }" class="myGrid"></div>
    </div>
  </body>

1 个答案:

答案 0 :(得分:2)

将您的HTML更改为

<body>
    <h1>Variants</h1>
    <div ng-app="myApp" ng-controller="MainCtrl">
      <div id="grid1" ui-grid="gridOptions" class="myGrid"></div>
    </div>
  </body>

目前您只是将数据传递给UI-Grid而不是选项,这将传递选项(例如columndef)和数据。