Angular Grid ag-grid columnDefs Dynamically change

匿名 (未验证) 提交于 2019-12-03 03:05:02

问题:

I have a problem about columnDefs change dynamically. Here is my gridOptions:

$scope.gridOptions = {         columnDefs: [],         enableFilter: true,         rowData: null,         rowSelection: 'multiple',         rowDeselection: true     }; 

and when I retrive data from server:

$scope.customColumns = [];  $http.post('/Home/GetProducts', { tableName: 'TABLE_PRODUCT' }).success(function (data) {     angular.forEach(data.Columns, function (c) {         $scope.customColumns.push(             {                 headerName: c.Name,                 field: c.Value,                 width: c.Width             }         );     });      $scope.gridOptions.columnDefs = $scope.customColumns;      $scope.gridOptions.rowData = data.Products;     $scope.gridOptions.api.onNewRows(); }).error(function () {  }); 

Note: here c is column object which comes from server.

When dynamically generating columns and assigning it to $scope.gridOptions.columnDefs there is blank grid but $scope.customColumns array is filled with right generated column objects. Please help me is this bug or I am doing something wrong?

回答1:

In ag-grid the columns in gridOptions are used once at grid initialisation. If you change the columns after initialisation, you must tell the grid. This is done by calling gridOptions.api.setColumnDefs()

Details of this api method are provided in the ag-grid documentation here.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!