Angular Grid Ag-grid columnDefs动态变化 [英] Angular Grid ag-grid columnDefs Dynamically change
问题描述
我对动态更改 columnDefs
有问题。这是我的gridOptions:
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 () {
});
注意:这里c是来自服务器的列对象。
动态生成列并将其分配给$ scope.gridOptions.columnDefs时,会出现空白网格,但 $ scope.customColumns
数组用正确生成的列对象填充。请帮助我解决这个错误,或者我做错什么了?
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?
推荐答案
在ag-grid中,gridOptions中的列在网格初始化。如果在初始化后更改列,则必须告知网格。通过调用 gridOptions.api.setColumnDefs()
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()
此api方法的详细信息在< a href = http://www.ag-grid.com/angular-grid-api/index.php rel = noreferrer> ag-grid文档在这里。
Details of this api method are provided in the ag-grid documentation here.
这篇关于Angular Grid Ag-grid columnDefs动态变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!