2017-07-27 59 views
0

我正在使用UI网格/ Angular 1.5作为工作项目,因此我需要在UI网格csv导出的末尾添加2行。在导出之前尝试过回调,但无法执行正确的逻辑。任何提示?将额外的行添加到UI Grid csv export

$scope.gridOptions.exporterFieldCallback = function(grid, row, col, value) { 
    grid.rows[grid.rows.length] = 'Hello \n World' 
} 

回答

0

我还没有使用UI Grid,但试试。

据我所知,你想在导出的CSV文件中添加2个新行。

在你的代码中,你想在exporterFieldCallback中添加行,但是对于每一行都会执行回调=>你有10行,它会执行10次=> add 10 x 2(rows)= 20 rows这是你不期望的。

我们有一个文件+ plunker here

我们修改这样

$scope.export = function() { 
    $scope.gridOptions.data.push({ 
     "name": "Hello world", 
     "gender": 1, 
     "company": "test company" 
    }); 
    $timeout(function() {//$timeout denote that you will wait for angular to complete their digest + render before call the exportation = you give UI grid to prepare NEW data before export it. 
     if ($scope.export_format == 'csv') { 
      var myElement = angular.element(document.querySelectorAll(".custom-csv-link-location")); 
      $scope.gridApi.exporter.csvExport($scope.export_row_type, $scope.export_column_type, myElement); 
     } else if ($scope.export_format == 'pdf') { 
      $scope.gridApi.exporter.pdfExport($scope.export_row_type, $scope.export_column_type); 
     }; 
    }) 
}; 
导出功能