农业网格不显示任何数据

ghe*_*tal 2 rendering asp.net-web-api angularjs ag-grid

我在与angularjs一起使用ag-grid。所以在控制器中,我用sql DB源填充了网格的行。为此,我正在进行webapi调用,该调用返回对象数组。以下是代码。

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.')
});


});
Run Code Online (Sandbox Code Playgroud)

但是当我运行页面时,它没有显示任何数据。当我调试并看到它以对象数组array [12]的形式返回response.data中的记录时。但它在网格中没有显示相同的内容。如果我分配我自己的数组(而不是response.data)类似于响应返回的内容,那么它将呈现数据。那么,问题出在哪里呢?

小智 5

我们有一个类似的问题。您可能需要使用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);
        },
Run Code Online (Sandbox Code Playgroud)