How to customize the CSV field separator?

If you are using the DataTables Extension to export the view into a CSV file, you may need to customize the field separator (by default it is a comma). To do so you would need to adapt and paste the following code into your theme's functions.php file ( see how):

add_filter( 'gravityview_datatables_js_options', 'my_gv_datatables_csv_export_separator', 20, 2 );

/**
 * Change the field separator when exporting a DataTable view into a CSV file
 * Replace MY_FIELD_SEPARATOR by the new separator character like '|' or ';'
 */
function my_gv_datatables_csv_export_separator( $config, $view_id ) {
	if( empty( $config['tableTools']['aButtons'] ) ) {
		return $config;
	}

	foreach ( $config['tableTools']['aButtons'] as &$button ) {
		if( 'csv' == $button['sExtends'] ) {
			$button['sFieldSeperator'] = 'MY_FIELD_SEPARATOR';
		}
	}

	return $config;
}

Read here how to add these code samples to your website: Where to put code samples.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us