Angularjs ag网格未显示任何数据
我正在使用ag网格和angularjs。所以在控制器中,我用sql DB源填充网格的行。为此,我正在进行webapi调用,该调用返回对象数组。下面是代码Angularjs ag网格未显示任何数据,angularjs,asp.net-web-api,rendering,ag-grid,Angularjs,Asp.net Web Api,Rendering,Ag Grid,我正在使用ag网格和angularjs。所以在控制器中,我用sql DB源填充网格的行。为此,我正在进行webapi调用,该调用返回对象数组。下面是代码 var module = angular.module("crud", ["agGrid"]); module.controller("crudCtrl", function ($scope, $http) { var columnDefs = [ { headerName: "Roll No", field: "RollNo", ed
var module = angular.module("crud", ["agGrid"]);
module.controller("crudCtrl", function ($scope, $http) {
var columnDefs = [
{ headerName: "Roll No", field: "RollNo", editable: true },
{ headerName: "Name", field: "Name", editable: true },
{ headerName: "Place", field: "PlaceName", editable: true },
{ headerName: "Birth Date", field: "dob", editable: true }
];
$scope.gridOptions = {
columnDefs: columnDefs,
rowData: [],
headerHeight: 42,
rowHeight: 32
};
$http.get("api/Student/GetAllStudents").then(function (response) {
$scope.gridOptions.rowData = response.data;
}, function (error) {
console.log('Oops! Something went wrong while saving the data.')
});
});
但是当我运行页面时,它没有显示任何数据。当我调试并看到它在response.data中返回记录作为数组的对象作为数组[12]。但它并没有在网格中显示相同的内容。如果我不指定response.data,而是指定自己的数组,类似于response返回的数组,那么它将呈现数据。那么,问题在哪里呢?我们也遇到了类似的问题。您可能需要使用gridOptions.onGridReady
onGridReady: () => {
//setup first yourColumnDefs and yourGridData
//now use the api to set the columnDefs and rowData
this.gridOptions.api.setColumnDefs(yourColumnDefs);
this.gridOptions.api.setRowData(yourGridData);
},
thanx。。。但在我的例子中,$scope.gridOptions.api.setRowData(res.data)解决了这个问题;添加数据和用新数组替换数据之间可能存在差异。我在接收新数据后添加了setRowData()调用,而不是在onGridReady函数中。