kavinhuh
kavinhuh

Reputation: 739

Adding dynamic column header to ng grid

Hi I want to add some columns dynamically (fetching from server) to the already populated column header,I am able to see the static column but the dynamic column are not updated , but I generate the gridoptions.columndef such that the dynamic columns are appended to it,but,in view its not reflecting. plunker

Upvotes: 0

Views: 1904

Answers (1)

lbrazier
lbrazier

Reputation: 2654

Here is a plunker that shows how you can do it: http://plnkr.co/edit/Ko0H8ZltkpngGodaB936?p=preview

   $scope.colDefs1 =  [{field: 'name', displayName: 'Name'}, {field:'age', displayName:'Age'}];            
   $scope.colDefs2 =  [{field: 'name', displayName: 'Name'}, {field:'age', displayName:'Age'}, {field:'occupation', displayName:'Occupation'}];  
   $scope.gridOptions = { 
       data: 'myData',
       columnDefs: 'colDefs1'
   };

   $scope.addColumns = function(){
     $scope.colDefs1 = $scope.colDefs2;
   }

See also this link to explain why I did it this way: https://github.com/angular-ui/ng-grid/issues/128

Update: Here is your plunker with todos.json converted to valid JSON and working: http://plnkr.co/edit/0eRwaBaOv7xaZbMHvbiR?p=preview

Upvotes: 1

Related Questions