angularjs ag-grid不显示行数据

时间:2017-04-19 19:23:00

标签: angularjs ag-grid

我正在使用ag-grid从服务器返回1行数据。数据从服务器返回,并在网格中设置,但数据未显示。 这是我的网格:

$scope.lastResultGridOptions = {
    rowData: $scope.jobResult,
    suppressCellSelection: true,
    suppressSorting: true,
    enableFilter: true,
    enableColResize: true,
    angularCompileRows: true,
    angularCompileHeaders: true,
    suppressMenuHide: true,
    columnDefs: [{
        field: 'StartDate',
        filter: 'text',
        headerName: 'Start Date',
        cellClass: 'wrap-text',
        minWidth: 10
    }, {
        field: 'EndDate',
        filter: 'text',
        headerName: 'End Date',
        cellClass: 'wrap-text',
        minWidth: 40
    }, {
        field: 'IsSuccess',
        filter: 'text',
        headerName: 'Result Status',
        cellClass: 'wrap-text',
        minWidth: 40
    }, {
        field: 'DateCompleted',
        filter: 'text',
        headerName: 'Date Completed',
        cellClass: 'wrap-text',
        minWidth: 40
    }]
};

在初始化期间调用此函数:

$scope.refreshLastResultGrid = function () {
jobResult.paged().$promise.then(function (results) {
    $scope.jobResult = results;
    $scope.lastResultGridOptions.rowData = $scope.jobResult;

    if ($scope.lastResultGridOptions.api) {
        $scope.lastResultGridOptions.api.setRowData();
        $scope.lastResultGridOptions.api.sizeColumnsToFit();
    }
}, function (error) {
 $scope.messageModalVariables = {
messageTitle: 'Error Refreshing Job Result',
messageDisplay: 'API Error. Could not retrieve job results.',
messageType: 'Error',
okIsHidden: false,
yesNoIsHidden: true
};
$scope.openMessageModal($scope.messageModalVariables);
        });
    };

$scope.refreshLastResultGrid();

这是对返回行的服务器的服务调用:

angular.module('vAnalyzeApp.services')
.factory('JobResult', function($resource, configSettings) {
 var jobresult = $resource(configSettings.apiServiceUrl + 'api/v1/jobresult', {}, {
   'paged': {
     method: 'GET',
     isArray: false,
     transformResponse: function(data, headers) {
      var count = headers('Count');
      return {
        count: angular.fromJson(count),
        results: angular.fromJson(data)
      };
    }
   }
 });
 return jobresult;
}); 

我在refreshLastResultGrid函数中调试,results从服务器返回并设置为$scope.lastResultGridOptions.rowDatasetRowData()函数完成且没有错误,但数据未显示在网格上。 这是网格的屏幕截图: enter image description here

为什么数据没有显示在网格中?

更新 结果对象是:

public class JobParameterDto
{
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public string SourceDB { get; set; }
    public string TargetDB { get; set; }
    public Nullable<DateTime> DateCompleted { get; set; }
    public Nullable<bool> IsSuccess { get; set; }
}

当我查看结果对象时,这是返回的正确数据:

  • StartDate:'01 / 01 / 2016T00:00:00'
  • EndDate:'11 / 01 / 2016T00:00:00'
  • TargetDB:'MainDB'
  • SourceDB:'WrhDB'
  • IsSuccess:null
  • DateCompleted:null

1 个答案:

答案 0 :(得分:0)

您应该使用api.setRowData来设置网格行。确保results.dataArray - ag-grid,期望rowDataArray

...
jobResult.paged().$promise.then(function (results) {
    $scope.jobResult = results instanceof Array?results:[results];
    if ($scope.lastResultGridOptions.api) {
        $scope.lastResultGridOptions.api.setRowData($scope.jobResult);
        $scope.lastResultGridOptions.api.refreshView();
        $scope.lastResultGridOptions.api.sizeColumnsToFit();
    }
}, function (error){
...