Another solution is to tell the grid that option data have been updated using the gridApi.core.notifyDataChange after setting the filename.
This way we can use csvExport(), etc. instead of rewriting the whole function again like in the accepted answer.
Her is an example for a modified export menu for excel and csv:
angular.module('app').controller('GridCrtl', ['$scope', '$filter', 'uiGridExporterService', 'uiGridExporterConstants', function ($scope, $filter, uiGridExporterService, uiGridExporterConstants) {
$scope.grid = {
exporterMenuExcel: false
, exporterMenuCsv: false
, exporterExcelSheetName: 'Export'
, onRegisterApi: function(gridApiRef) {
gridApi = gridApiRef;
}
, gridMenuCustomItems: [{
{
title: 'CSV Export (visible)'
, action: function() {
$scope.grid.exporterCsvFilename = "example_"+$filter('date')(new Date(),'yyyy-MM-dd_HH-mm-ss')+".csv"
gridApi.core.notifyDataChange(uiGridConstants.dataChange.OPTIONS);
uiGridExporterService.csvExport(gridApi.grid, uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE);
}
, order: 1
}
,{
title: 'CSV Export (all)'
, action: function() {
$scope.grid.exporterCsvFilename = "example_"+$filter('date')(new Date(),'yyyy-MM-dd_HH-mm-ss')+".csv"
gridApi.core.notifyDataChange(uiGridConstants.dataChange.OPTIONS);
uiGridExporterService.csvExport(gridApi.grid, uiGridExporterConstants.ALL, uiGridExporterConstants.ALL);
}
, order: 2
}
,{
title: 'Excel Export (visible)'
, action: function() {
$scope.grid.exporterCsvFilename = "example_"+$filter('date')(new Date(),'yyyy-MM-dd_HH-mm-ss')+".xlsx"
gridApi.core.notifyDataChange(uiGridConstants.dataChange.OPTIONS);
uiGridExporterService.excelExport(gridApi.grid, uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE);
}
, order: 3
}
,{
title: 'Excel Export (all)'
, action: function() {
$scope.grid.exporterCsvFilename = "example_"+$filter('date')(new Date(),'yyyy-MM-dd_HH-mm-ss')+".xlsx"
gridApi.core.notifyDataChange(uiGridConstants.dataChange.OPTIONS);
uiGridExporterService.excelExport(gridApi.grid, uiGridExporterConstants.ALL, uiGridExporterConstants.ALL);
}
, order: 4
}]
}
};
}]);