OvoiDs OvoiDs - 4 months ago 15
Javascript Question

AngularJs & ui-grid: grid is ignoring gridOptions

I'm having issues with ui-grid to disable gridMenu and to rename my columns. I've made a plnkr so you can see: 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':

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>

Answer

Change your HTML to

<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.

Comments