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
Add a comment
|
1 Answer
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
4 Comments
kavinhuh
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.
kavinhuh
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.
lbrazier
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
lbrazier
Did this help you figure out your problem? If so, would you kindly upvote/accept?