Forum Replies Created

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter Tiquelou

    (@arnie123)

    I just checked out the github page, if you want I can go ahead and add the code from my end. Let me know!

    Thread Starter Tiquelou

    (@arnie123)

    Yes, it is resolved, thanks – I was going to ‘Resolve’ it once I replied to your rating remarks ??

    Thread Starter Tiquelou

    (@arnie123)

    Hi Tobias,

    Did I tell you how awesome you are? ??

    I agree when you say DataTables Documentation is redundant and hence not required in TablePress. What I meant was, it would be good to have an example of how to use the ‘Custom Command’ feature. To elaborate, if I want to hide a particular row, how to key in the DataTable code into the Custom Code field. It took me some time to figure it out, since it’s a single line entry. Also, am not too sure if you can pass a callback parameter using the custom code field? If only some of the parameters are supported, then it would be good to have a list of those in the documentation.

    I never disputed the presence of valid use cases of the show/hide feature, as my guess would be that it was put there after people requested for it :-). I just thought it would be good to have a documentation on how it can prove useful on different scenarios, or when people can use this feature. Don’t know if it makes sense to you?

    Thanks for making this plugin open source, I have already made changes to the plugin, so you can say I have started on the improvements already ??

    If you need help with anything at all, please do get in touch with me at [email protected]. Do drop by my site if you can – it’s https://www.arnabdesigns.in

    Cheers and Thanks for Everything!

    Thread Starter Tiquelou

    (@arnie123)

    Hey Tobias,

    I made some changes to make the max selection work, could you update your plugin with the same so that next time I can update and not lose the functionality?

    <?php
    /*
    Plugin Name: TablePress Extension: DataTables ColumnFilterWidgets
    Plugin URI: https://tablepress.org/extensions/datatables-columnfilterwidgets/
    Description: Custom Extension for TablePress to add the DataTables ColumnFilterWidgets functionality
    Version: 1.4
    Author: Tobias B?thge
    Author URI: https://tobias.baethge.com/
    */
    
    // Shortcode: [table id=123 datatables_columnfilterwidgets=true datatables_columnfilterwidgets_exclude_columns=2,3,4 datatables_columnfilterwidgets_separator="," /]
    
    /**
     * Register necessary Plugin Filters
     */
    add_filter( 'tablepress_shortcode_table_default_shortcode_atts', 'tablepress_add_shortcode_parameters_columnfilterwidgets' );
    add_filter( 'tablepress_table_js_options', 'tablepress_add_columnfilterwidgets_js_options', 10, 3 );
    add_filter( 'tablepress_datatables_parameters', 'tablepress_add_columnfilterwidgets_parameters', 10, 4 );
    if ( ! is_admin() )
    	add_action( 'wp_enqueue_scripts', 'tablepress_enqueue_columnfilterwidgets_css' );
    
    /**
     * Add "datatables_columnfilterwidgets" as a valid parameter to the [table /] Shortcode
     */
    function tablepress_add_shortcode_parameters_columnfilterwidgets( $default_atts ) {
    	$default_atts['datatables_columnfilterwidgets'] = false;
    	$default_atts['datatables_columnfilterwidgets_exclude_columns'] = '';
    	$default_atts['datatables_columnfilterwidgets_separator'] = '';
    	$default_atts['datatables_columnfilterwidgets_max_selections'] = '';
    	return $default_atts;
    }
    
    /**
     * Pass "datatables_columnfilterwidgets" from Shortcode parameters to JavaScript arguments
     */
    function tablepress_add_columnfilterwidgets_js_options( $js_options, $table_id, $render_options ) {
    	$js_options['datatables_columnfilterwidgets'] = $render_options['datatables_columnfilterwidgets'];
    	$js_options['datatables_columnfilterwidgets_exclude_columns'] = $render_options['datatables_columnfilterwidgets_exclude_columns'];
    	$js_options['datatables_columnfilterwidgets_separator'] = $render_options['datatables_columnfilterwidgets_separator'];
    	// Custom Code
    	$js_options['datatables_columnfilterwidgets_max_selections'] = $render_options['datatables_columnfilterwidgets_max_selections'];
    	// ... Ends
    	// register the JS
    	if ( '' != $js_options['datatables_columnfilterwidgets'] ) {
    		$js_columnfilterwidgets_url = plugins_url( 'js/ColumnFilterWidgets.js', __FILE__ );
    		wp_enqueue_script( 'tablepress-columnfilterwidgets', $js_columnfilterwidgets_url, array( 'tablepress-datatables' ), '1.3', true );
    	}
    
    	return $js_options;
    }
    
    /**
     * Add "sDom" parameter, if ColumnFilterWidgets is enabled for the table
     */
    function tablepress_add_columnfilterwidgets_parameters( $parameters, $table_id, $html_id, $js_options ) {
    
    	if ( ! $js_options['datatables_columnfilterwidgets'] )
    		return $parameters;
    
    	$parameters['sDom'] = '"sDom": "Wlfrtip"';
    
    	$column_filter_widget_parameters = array();
    
    	if ( '' != $js_options['datatables_columnfilterwidgets_exclude_columns'] ) {
    		$columns = explode( ',', $js_options['datatables_columnfilterwidgets_exclude_columns'] );
    		foreach ( $columns as $idx => $column ) {
    			$columns[$idx] = (int)( trim($column) ) - 1;
    		}
    		$columns = implode( ',', $columns );
    		if ( '' != $columns )
    			$column_filter_widget_parameters['oColumnFilterWidgets'] = '"aiExclude": [ ' . $columns . ' ]';
    	}
    	// Custom Code
    	if ( '' != $js_options['datatables_columnfilterwidgets_max_selections'] ) {
    		$limit = $js_options['datatables_columnfilterwidgets_max_selections'];
    		if ( '' != $limit )
    			$column_filter_widget_parameters['datatables_columnfilterwidgets_max_selections'] = '"iMaxSelections": ' . $limit;
    	}
    	// ... Ends
    	if ( '' != $js_options['datatables_columnfilterwidgets_separator'] ) {
    		$separator = addslashes( $js_options['datatables_columnfilterwidgets_separator'] );
    		$separator = str_replace( '"', '\"', $separator ); // some simple escaping
    		$column_filter_widget_parameters['sSeparator'] = '"sSeparator": "' . $separator . '"';
    	}
    
    	if ( ! empty( $column_filter_widget_parameters ) ) {
    		$column_filter_widget_parameters = implode( ',', $column_filter_widget_parameters );
    		$parameters['oColumnFilterWidgets'] = '"oColumnFilterWidgets": { ' . $column_filter_widget_parameters . ' }';
    	}
    
    	return $parameters;
    }
    
    /**
     * Enqueue ColumnFilterWidgets CSS
     */
    function tablepress_enqueue_columnfilterwidgets_css() {
    	$columnfilterwidgets_css_url = plugins_url( "css/ColumnFilterWidgets.css", __FILE__ );
    	wp_enqueue_style( 'tablepress-columnfilterwidgets-css', $columnfilterwidgets_css_url, array(), '1.2' );
    }

    Thanks a Ton!!

    Thread Starter Tiquelou

    (@arnie123)

    … and so are you! ??

    Your first impression was in fact correct. I actually wanted the filter dropdowns only for the hidden columns, so the code should have been:
    [table id=123 datatables_columnfilterwidgets=true datatables_columnfilterwidgets_exclude_columns=4,5,6 /]

    Thanks for the DataTables code optimization!

    I’m working on the PHP file, will post the code here OR will ask you to help me with it ??

    Thread Starter Tiquelou

    (@arnie123)

    Hey,

    The plugin works great – no complaints there… in fact, I gave the 4 stars as soon as I used it for the very 1st time :)… the plugin works great, the only thing sorely missing is the documentation. I can help you write it if you are pressed for time, but some of the features need explaining is what I feel. e.g.

    • Custom Commands: How to use it? (I figured it out eventually, but wont it be nice if we had a documentation for the same?)
    • Hide/Show Columns: Why? If I dont want any columns, I can just delete it. Need to illustrate some use cases wherein this might come in handy maybe?

    We can also build a few easy customizations, which would make this plugin best suited for even a wider range of applications. Again, I’m ready to help you all I can :).

    Thread Starter Tiquelou

    (@arnie123)

    Thanks Tobias!

    I got most of it to work. Will paste how I did it here for the benefit of other users who want something similar.

    Step 1: Hide Columns using ‘Custom Commands’
    "aoColumnDefs": [{ "bVisible":false, "aTargets": [ 0 ]} ,{ "bVisible":false, "aTargets": [ 1 ] },{ "bVisible":false, "aTargets": [ 2 ] }]

    Step 2: Activate and Configure DataTables ColumnFilterWidgets
    [table id=123 datatables_columnfilterwidgets=true datatables_columnfilterwidgets_exclude_columns=1,2,3 /]

    One thing worth noticing is that Datatables uses a 0-based index whereas DataTables ColumnFilterWidgets extension uses 1-based index.

    The current challenge I’m facing is applying only ONE keyword at a time for any filter; i.e. if you select a keyword for a filter it should reset any previous values selected.

    Wonder if you can help me with that?

    Thread Starter Tiquelou

    (@arnie123)

    This extension MIGHT be what I need:
    https://tablepress.org/download/extension/tablepress-datatables-column-filter-widgets.zip
    (derived from: https://datatables.net/extras/thirdparty/ColumnFilterWidgets/DataTables/extras/ColumnFilterWidgets/)

    If only it can be used for hidden columns, and for selective columns. Please advise!

Viewing 8 replies - 1 through 8 (of 8 total)