Parameters DataTables
-
Hello, thanks you for your work.
When i export my table in pdf, i would like a landscape pdf with only 3 columns.
So, in my table parameters, i add :
"aoColumnDefs": [ { "sType": "formatted-num", "aTargets": [ 8,9 ] } ], "aButtons": [ { "sExtends": "copy", "sButtonText": "" }, { "sExtends": "csv", "sButtonText": "" }, { "sExtends": "xls", "sButtonText": "" }, { "sExtends": "pdf", "sPdfOrientation": "landscape", "sButtonText": "", "mColumns": [ 0, 1, 4 ] }, { "sExtends": "print", "sButtonText": "" } ]But the aButtons parameter doesn’t work…:(
-
Hi,
thanks for your question, and sorry for the trouble.
The
aButtonsparameter is a parameter for the DataTables TableTools Extension, and not for DataTables itself.
You will therefore need to make this change in the PHP file that generates the TableTools JS command directly.
For the TablePress DataTables TableTools Extension, that’s the file “tablepress-datatables-tabletools.php”. Specifically, you’ll want to modify line 60 there.Regards,
Tobiashi, thanks for the answer.
I change this line :
$tabletools_options = '{ "sSwfPath": "' . $swf_path . '", "aButtons": [ { "sExtends": "copy", "sButtonText": "" }, { "sExtends": "csv", "sButtonText": "" }, { "sExtends": "xls", "sButtonText": "" }, { "sExtends": "pdf", "sPdfOrientation": "landscape", "sButtonText": "", "mColumns": [ 0, 1, 4 ], "sButtonText": "" }, { "sExtends": "print", "sButtonText": "" } ] }';But no effect….:(
Hi,
Can you please post a link to the page with the table where this problem happens, so that I can take a direct look? Thanks!
Unfortunately, I can not promise a solution though, as I’m not that familiar with the internals of the TableTools add-on 🙁
Also, where did you get this code from?Regards,
Tobiashi,
yes, of course.
here the site : http://www.lenclosdesvins.com/catalogue/and here for code : http://datatables.net/extras/tabletools/button_options
with sPdfOrientation and mColumns.
Thanks you for your help
Hi,
thanks for the link!
I don’t see the modified JS code at the bottom of the page (when you use “View source” in the browser).
Did you maybe not edit the correct line in the PHP file, but the other one that is commented out?Regards,
Tobiashi,
i modified tablepress-datatables-tabletools.php.
here the code :
<?php /* Plugin Name: TablePress Extension: DataTables TableTools Plugin URI: http://tablepress.org/extensions/datatables-tabletools/ Description: Custom Extension for TablePress to add the DataTables TableTools functionality Version: 1.1 Author: Tobias Bäthge Author URI: http://tobias.baethge.com/ */ /** * Register necessary Plugin Filters */ add_filter( 'tablepress_shortcode_table_default_shortcode_atts', 'tablepress_add_shortcode_parameters_tabletools' ); add_filter( 'tablepress_table_js_options', 'tablepress_add_tabletools_js_options', 10, 3 ); add_filter( 'tablepress_datatables_command', 'tablepress_add_tabletools_js_command', 10, 5 ); if ( ! is_admin() ) add_action( 'wp_enqueue_scripts', 'tablepress_enqueue_tabletools_css' ); /** * Add "datatables_tabletools" as a valid parameter to the [table /] Shortcode */ function tablepress_add_shortcode_parameters_tabletools( $default_atts ) { $default_atts['datatables_tabletools'] = false; return $default_atts; } /** * Pass "datatables_tabletools" from Shortcode parameters to JavaScript arguments */ function tablepress_add_tabletools_js_options( $js_options, $table_id, $render_options ) { $js_options['datatables_tabletools'] = $render_options['datatables_tabletools']; // register the JS if ( $js_options['datatables_tabletools'] ) { $js_tabletools_url = plugins_url( 'js/TableTools.min.js', __FILE__ ); wp_enqueue_script( 'tablepress-tabletools', $js_tabletools_url, array( 'tablepress-datatables' ), '2.1.5', true ); } return $js_options; } /** * Evaluate "datatables_tabletools" parameter and add corresponding JavaScript code, if needed */ function tablepress_add_tabletools_js_command( $command, $html_id, $parameters, $table_id, $js_options ) { if ( ! $js_options['datatables_tabletools'] ) return $command; $table_wrapper = "{$html_id}_wrapper"; $html_id = str_replace( '-', '_', $html_id ); $table_name = "oTable_{$html_id}"; $tabletools_name = "oTableTools_{$html_id}"; $command = substr( $command, 0, -1 ); // removing ; at the end $swf_path = plugins_url( 'swf/copy_csv_xls_pdf.swf', __FILE__ ); // with text (somme CSS needs to commented out!): //$tabletools_options = '{ "sSwfPath": "' . $swf_path . '", "aButtons": [ "copy", "print", { "sExtends": "collection", "sButtonText": "Save as", "aButtons": [ "csv", "xls", "pdf" ] } ] }'; // with images: $tabletools_options = '{ "sSwfPath": "' . $swf_path . '", "aButtons": [ { "sExtends": "copy", "sButtonText": "" }, { "sExtends": "csv", "sButtonText": "" }, { "sExtends": "xls", "sButtonText": "" }, { "sExtends": "pdf", "sPdfOrientation": "landscape", "sButtonText": "", "mColumns": [ 0, 1, 4 ], "sButtonText": "" }, { "sExtends": "print", "sButtonText": "" } ] }'; $command = "var {$table_name} = {$command}, {$tabletools_name} = new TableTools({$table_name}, {$tabletools_options}); $('#{$table_wrapper}').before({$tabletools_name}.dom.container);"; return $command; } function tablepress_enqueue_tabletools_css() { $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; $tabletools_css_url = plugins_url( "css/TableTools{$suffix}.css", __FILE__ ); wp_enqueue_style( 'tablepress-tabletools-css', $tabletools_css_url, array(), '2.1.5' ); }Hi,
that appears to be correct, but the code is still not in the page…
Did you really modify this file on the server?
Are you maybe using a caching plugin? You would then have to flush the cache there, to make the code work.Regards,
TobiasHi,
hum….maybe it’s an other problem…..
I waited 8 hours, modified the code and nothing…..
it seems rather that $ tabletools_options not be used / read ?Regards
Hi,
ah, I just noticed that you are using the combined TableTools+FixedHeader Extension. You’ll then of course need to modify the PHP file of that Extension…
Can you please try that?Regards,
Tobiashi,
That’s was it ! Perfect !
Thanks you very much for all.Regards
Guillaume
resolved
Hi,
no problem, you are very welcome! 🙂 Good to hear that this helped!
Best wishes,
TobiasP.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!
The topic ‘Parameters DataTables’ is closed to new replies.