0

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

0

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

yea It works fine if we define the data locally but I am unable to push it incase of fetching data from server say I get the the data coldefs2 from server , I am unable to push it to coldefs1.
but why the same json is working fine when defined locally but not from todo.json,I find the difference is th double quotes in the field value.why is it like that.
It's coming in from the file as a string. It would need to be JSON parsed back to an object for use in the grid, but it's not valid JSON. See zachleat.com/web/javascript-objects-are-not-json and jsonlint.com
Did this help you figure out your problem? If so, would you kindly upvote/accept?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.