我還沒有使用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);
};
})
};
導出功能