How to customize the Excel export file name
When exporting your DataTables View to an Excel file, the default file name combines the View name and your website name.
This snippet uses the gravityview/datatables/button_excel filter, which only affects the Excel export button. Your View’s DataTables layout needs the Excel button enabled under View Settings → DataTables → Buttons.
Add your preferred file name between the single quotes on the $button_config['filename'] line below:
add_filter( 'gravityview/datatables/button_excel','gravityview_excel_export_settings', 10 ,2 );
/**
* Set a custom file name for the DataTables Excel export button.
*
* @param array $button_config Associative array of button options. Set 'filename' to the exported file name (without extension), and 'title' to the heading shown at the top of the file — use an empty string to omit it.
* @param int $view_id ID of the View being exported.
*
* @return array Modified button configuration.
*/
function gravityview_excel_export_settings( $button_config = array(), $view_id ) {
$button_config['filename'] = 'YOUR-NEW-FILENAME-HERE';
$button_config['title'] = '';
return $button_config;
}$button_config['filename'] sets the file name only — DataTables automatically appends the .xlsx extension. $button_config['title'] controls the heading shown at the top of the exported spreadsheet; the snippet above clears it by setting it to an empty string.
To customize other export buttons (PDF, CSV, Print, Column Visibility) the same way, use the matching gravityview/datatables/button_{$button} filter, or hook gravityview/datatables/button to modify every export button at once.
If you’re not sure where to add code samples, please see the following article: Where to put code samples
