简体   繁体   English

AngularJs和ui-grid:网格正在忽略gridOptions

[英]AngularJs & ui-grid: grid is ignoring gridOptions

I'm having issues with ui-grid to disable gridMenu and to rename my columns. 我在ui-grid上遇到问题,以禁用gridMenu并重命名我的列。 I've made a plnkr so you can see: https://plnkr.co/edit/EGhvBGOJCKPzfupjCROx?p=preview 我做了一个plnkr,所以您可以看到: https ://plnkr.co/edit/EGhvBGOJCKPzfupjCROx?p=preview

As you can see in script.js, I'd like my columns to be named 'banana', 'chrom' and 'position': 如您在script.js中所看到的,我希望将我的列命名为“香蕉”,“色度”和“位置”:

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}
            ]
    };

}]);

Data is looking like that: 数据看起来像这样:

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

And here is how I call my grid: 这是我如何称呼我的网格:

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

Change your HTML to 将您的HTML更改为

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

At the moment you are only passing the data to the UI-Grid and not the options, this will pass the options (such as the columndefs) and the data. 目前,您仅将数据传递给UI-Grid而不是选项,这将传递选项(例如columndefs)和数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM