Purpose
Modify the filename used when exporting a DataTable as a file. This filter allows you to dynamically adjust the filename based on specific conditions or payload data.
Usage
add_filter( "wr_datatable_as_file_filename", array( $this, "modify_datatable_file_filename" ), 10, 3 );
Parameters
$filename (string)
: The default filename for the exported DataTable file.$payload (array)
: Data associated with the export request.$object (mixed)
: The DataTable object or context associated with the export.
Use Case
This functionality is useful when:
- You need to customize the filenames of exported DataTables for organizational or contextual purposes.
- Filenames should include additional information, such as dynamic titles, timestamps, or identifiers.
Implementation Example
The following example prepends the string “test” to the filename if certain conditions in the payload are met:
add_filter( "wr_datatable_as_file_filename", array( $this, "modify_datatable_file_filename" ), 10, 3 );
public function modify_datatable_file_filename( $filename, $payload, $object ) {
if ( $this->filename_should_be_modified( $payload ) ) {
$new_title = "test"
$filename = $new_title . " " . $filename;
}
return $filename;
}