2017-07-27 58 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); 
     }; 
    }) 
}; 
導出功能