Reputation: 61
I am not able to update the ag-gird girdOptions columnDefs by accessing the $scope.girdOptions.api.setColumnDefs.
What I am trying to achieve is group by the table with a different value.
var masterColumnDefs = [
{headerName: 'Name', field: 'name',
// left column is going to act as group column, with the expand / contract controls
cellRenderer: 'group',
// we don't want the child count - it would be one each time anyway as each parent
// not has exactly one child node
cellRendererParams: { suppressCount: true }
},
{headerName: 'Account', field: 'account'},
{headerName: 'Calls', field: 'totalCalls'},
{headerName: 'Minutes', field: 'totalMinutes', cellFormatter: minuteCellFormatter}
];
The cellRenderer: 'group' code is something they have inbuilt for handling the grouping so this example contains rendering a grid inside the row when expanded.
Though they have feasibility for doing the group by dynamically with the pivot menu options, I have a requirement for rendering a grid inside the row so the JSON I am getting in the response is similar to the rowData in the Plunkr.
Hence, I can not have the pivot option for grouping dynamically.
The issue that I am trying to solve here is to update the above masterColumnDefs by modifying it
` masterColumnDefs = [
{headerName: 'Name', field: 'name'
},
{headerName: 'Account', field: 'account',
// left column is going to act as group column, with the expand / contract controls
cellRenderer: 'group',
// we don't want the child count - it would be one each time anyway as each parent
// not has exactly one child node
cellRendererParams: { suppressCount: true }},
{headerName: 'Calls', field: 'totalCalls'},
{headerName: 'Minutes', field: 'totalMinutes', cellFormatter: minuteCellFormatter}
];`
and update the gridOptions with
$scope.gridOptions.api.setColumnDefs(masterColumnDefs);
Nothing helps me out.
May be some other solution could also do that functionality but I am not getting it.
Points to note:
Any ideas would be a great help.
Upvotes: 1
Views: 850
Reputation: 61
This was quite tricky when you are using a javascript lib for you angular app.
I was able to get it done by calling the api inside a timeout function.
$timeout(function(){
$scope.gridOptions.api.setColumnDefs(masterColumnDefs);
}, 0);
Where as if you print the $scope.gridOptions above the $scope.gridOptions.api.setColumnDefs(masterColumnDefs); without the timeout function note that the object does not have api or columnApi keys.
But when you wrap the
$scope.gridOptions.api.setColumnDefs(masterColumnDefs);
with a timeout function then in the console, you can see the object with api and columnApi so now it will update the gridOptions with the values that you have.
This has not been explained or documented anywhere in the ag-grid website as far as I have analyzed it.
Hope this helps!
Upvotes: 2