【发布时间】:2018-09-09 18:11:56
【问题描述】:
我正在使用 ag-grid 将值显示到网格中。但是使用 setRowData 不会将值加载到网格中。下面是我在 setTimeOut 函数中调用 setRowData 的代码,因为它抛出 api 是未定义:
<html>
<head>
</head>
<body ng-app ng-controller="CustController as custCtrl">
<div ag-grid="custCtrl.gridOptions" id="myGrid" style="height:
115px;width:500px;" class="ag-fresh"></div>
</body>
</html>
var app = angular.module('myApp');
app.controller('CustController', function($scope, $http) {
var columnDefs = [
{headerName: "Customer Name", field: "custName"},
{headerName: "Address", field: "address"},
{headerName: "Ph NO", field: "phNo"}
];
var rowData = [
{custName: "A", address: "xyz", phNo: '123-123-1234'},
{custName: "B", address: "lmn", phNo: '345-456-5672'},
{custName: "C", address: "pqr", phNo: '903-456-2345'}
];
var gridOptions = {
columnDefs: columnDefs,
enableColResize: true,
rowBuffer:0,
enableSorting: true,
enableFilter: true,
rowHeight: 30,
headerHeight: 35,
sizeColumnsToFit: true,
onGridReady: function () {
setTimeout( function(){
$scope.gridOptions.api.setRowData(rowData);
},5000);
},
suppressLoadingOverlay: true,
pagination: true
};
});
【问题讨论】: