2017-02-10 15 views
0

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


}); 

ただし、ページを実行するとデータが表示されません。私がデバッグして参照すると、配列[12]としてオブジェクトの配列としてresponse.dataのレコードが返されます。それはグリッドに同じものを表示していません。 response.dataの代わりに私が自分の配列を代入して、応答が返すものと同じようにすると、データがレンダリングされます。では、問題はどこにありますか?

答えて

1

私たちも同様の問題がありました。あなたは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); 
     }, 
+0

ありがとうを使用する必要があるかもしれません...しかし、私の場合、それは$ scope.gridOptions.api.setRowData(res.data)によって解決しまいました。 – ghetal

関連する問題