• Resolved guil182

    (@guil182)


    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…:(

    https://www.ads-software.com/plugins/tablepress/

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your question, and sorry for the trouble.

    The aButtons parameter 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,
    Tobias

    Thread Starter guil182

    (@guil182)

    hi, 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….:(

    Plugin Author TobiasBg

    (@tobiasbg)

    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,
    Tobias

    Thread Starter guil182

    (@guil182)

    hi,

    yes, of course.
    here the site : https://www.lenclosdesvins.com/catalogue/

    and here for code : https://datatables.net/extras/tabletools/button_options

    with sPdfOrientation and mColumns.

    Thanks you for your help

    Plugin Author TobiasBg

    (@tobiasbg)

    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,
    Tobias

    Thread Starter guil182

    (@guil182)

    hi,

    i modified tablepress-datatables-tabletools.php.

    here the code :

    <?php
    
    /*
    
    Plugin Name: TablePress Extension: DataTables TableTools
    
    Plugin URI: https://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: https://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' );
    
    }
    Plugin Author TobiasBg

    (@tobiasbg)

    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,
    Tobias

    Thread Starter guil182

    (@guil182)

    Hi,

    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

    Plugin Author TobiasBg

    (@tobiasbg)

    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,
    Tobias

    Thread Starter guil182

    (@guil182)

    hi,

    That’s was it ! Perfect !
    Thanks you very much for all.

    Regards

    Guillaume

    Thread Starter guil182

    (@guil182)

    resolved

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! ?? Good to hear that this helped!

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Parameters DataTables’ is closed to new replies.