我还没有使用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);
};
})
};
导出功能