2017-02-10 3 views
0

Ich benutze Ag-Grid mit angularjs. Im Controller bearbeite ich also Zeilen mit der SQL DB-Quelle. Dafür mache ich einen Webapi-Aufruf, der ein Array von Objekten zurückgibt. Folgendes ist der Code.ag-grid zeigt keine Daten an

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


}); 

aber wenn ich die Seite ausführen zeigt es keine Daten. Wenn ich debugge und sehe, gibt es Datensätze in response.data als ein Array von Objekt als Array [12] zurück. aber es zeigt nicht dasselbe im Raster. Wenn ich anstelle von response.data ein eigenes Array ähnlich dem zurückgebe, was die Antwort zurückgibt, werden die Daten gerendert. Also, wo ist das Problem?

Antwort

1

Wir hatten ein ähnliches Problem. Sie können 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

thanx ... aber in meinem Fall verwenden müssen, wurde es von $ scope.gridOptions.api.setRowData (res.data) gelöst; – ghetal