Title: Using Data from hidden columns
Last modified: August 21, 2016

---

# Using Data from hidden columns

 *  Resolved [Tiquelou](https://wordpress.org/support/users/arnie123/)
 * (@arnie123)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/using-data-from-hidden-columns/)
 * Hi,
 * Awesome plugin, by the way! 🙂
 * I see that you have an option of ‘hide’-ing and ‘show’-ing particular rows / 
   columns. Can you briefly explain the usage of the same?
 * I came across your plugin when there was a requirement of displaying various 
   pricing options for a particular product in a tabular format. The data is to 
   be read / imported from a CSV / XLS / XSLX file. The 1st 3 columns have the data
   which is to be used to filter the pricing options. I have hidden the 1st 3 columns,
   but wonder how the filtering can be done.
 * Any help would be much appreciated.. thanks in advance!
 * [http://wordpress.org/plugins/tablepress/](http://wordpress.org/plugins/tablepress/)

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

 *  Thread Starter [Tiquelou](https://wordpress.org/support/users/arnie123/)
 * (@arnie123)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/using-data-from-hidden-columns/#post-4299752)
 * This extension MIGHT be what I need:
    [http://tablepress.org/download/extension/tablepress-datatables-column-filter-widgets.zip](http://tablepress.org/download/extension/tablepress-datatables-column-filter-widgets.zip)(
   derived from: [http://datatables.net/extras/thirdparty/ColumnFilterWidgets/DataTables/extras/ColumnFilterWidgets/](http://datatables.net/extras/thirdparty/ColumnFilterWidgets/DataTables/extras/ColumnFilterWidgets/))
 * If only it can be used for hidden columns, and for selective columns. Please 
   advise!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/using-data-from-hidden-columns/#post-4299772)
 * Hi,
 * thanks for your question.
 * Yes, using that Extension should work here. You’ll need a different approach 
   on hiding the columns though. Instead of hiding them on the “Edit” screen of 
   the table (with the checkboxes and the “Selected rows/columns: Hide” buttons),
   you’ll need to hide them via JavaScript or CSS.
 * I suggest that you set-up the table with those columns visible first, and then
   we’ll proceed with hiding them, after everything works.
    To only show a drop 
   down for certain columns, you can use the extra Shortcode parameter that is explained
   on the page [http://tablepress.org/extensions/datatables-columnfilterwidgets/](http://tablepress.org/extensions/datatables-columnfilterwidgets/)
 * Regards,
    Tobias
 *  Thread Starter [Tiquelou](https://wordpress.org/support/users/arnie123/)
 * (@arnie123)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/using-data-from-hidden-columns/#post-4299809)
 * 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?
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/using-data-from-hidden-columns/#post-4299813)
 * Hi,
 * wow, you are quick 🙂
    Yes, that’s what I meant with hiding the columns via JS.
   If you want, you can shorten the code to
 *     ```
       "aoColumnDefs": [{ "bVisible":false, "aTargets": [ 0, 1, 2 ] }]
       ```
   
 * Now, as you are actually hiding the drop down for exactly these columns (my first
   impression was that that would not be the case), you could indeed actually hide
   them with the checkboxes/buttons on the “Edit” screen that I mentioned above,
   and would then neither need the “Custom Command” nor the extra Shortcode parameter.
 * Regarding one keyword at a time: I’m not sure about resetting, but as it seems,
   the actual ColumnFilterWidgets JS allows to set a maximum number of selections:
   
   [http://datatables.net/extras/thirdparty/ColumnFilterWidgets/DataTables/extras/ColumnFilterWidgets/max-selections.html](http://datatables.net/extras/thirdparty/ColumnFilterWidgets/DataTables/extras/ColumnFilterWidgets/max-selections.html)(
   There’s no Shortcode parameter for that in the TablePress Extension right now,
   though. That would have to be added to the PHP file.)
 * Regards,
    Tobias
 * P.S.: I’d appreciate if you could take a look at my reply to your rating at [http://wordpress.org/support/topic/easy-import-extensive-customization-and-great-ease-of-use?replies=2#post-4857712](http://wordpress.org/support/topic/easy-import-extensive-customization-and-great-ease-of-use?replies=2#post-4857712)
   and maybe post some details there. Thanks!
 *  Thread Starter [Tiquelou](https://wordpress.org/support/users/arnie123/)
 * (@arnie123)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/using-data-from-hidden-columns/#post-4299824)
 * … 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](https://wordpress.org/support/users/arnie123/)
 * (@arnie123)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/using-data-from-hidden-columns/#post-4299832)
 * 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: http://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: http://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!!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/using-data-from-hidden-columns/#post-4299836)
 * Hi,
 * alright, thanks for the clarification. That in fact makes more sense, and you
   won’t need the Hide feature on the “Edit” screen then.
 * And thanks for those modifications, I’ll gladly add them to the Extension!
    (
   Note that you can’t lose your modifications through an an automatic update right
   now, as the Extension is not in the wordpress.org repository. I’ll probably add
   support for automatic updates from my server though, soon.)
 * (And I assume that the original question of this thread is fixed with this solution,
   so I’ll go ahead and “resolve” this thread. Feel free to post any further questions,
   of course.)
 * Regards,
    Tobias
 * P.S.: I also replied to your further remarks on the rating.
 *  Thread Starter [Tiquelou](https://wordpress.org/support/users/arnie123/)
 * (@arnie123)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/using-data-from-hidden-columns/#post-4299840)
 * Yes, it is resolved, thanks – I was going to ‘Resolve’ it once I replied to your
   rating remarks 🙂
 *  Thread Starter [Tiquelou](https://wordpress.org/support/users/arnie123/)
 * (@arnie123)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/using-data-from-hidden-columns/#post-4299843)
 * I just checked out the github page, if you want I can go ahead and add the code
   from my end. Let me know!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/using-data-from-hidden-columns/#post-4299922)
 * Hi,
 * thanks for the confirmation!
 * You won’t be able to add this code on Github directly, as this is a TablePress
   Extension, and I don’t have those on Github yet.
 * I’ll however add the code to the Extension manually, and then release a new version
   on [http://tablepress.org/extensions/datatables-columnfilterwidgets/](http://tablepress.org/extensions/datatables-columnfilterwidgets/)
   probably later today.
 * Regards,
    Tobias

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

The topic ‘Using Data from hidden columns’ is closed to new replies.

 * ![](https://ps.w.org/tablepress/assets/icon.svg?rev=3192944)
 * [TablePress - Tables in WordPress made easy](https://wordpress.org/plugins/tablepress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/tablepress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/tablepress/)
 * [Active Topics](https://wordpress.org/support/plugin/tablepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/tablepress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/tablepress/reviews/)

## Tags

 * [filter](https://wordpress.org/support/topic-tag/filter/)
 * [hide](https://wordpress.org/support/topic-tag/hide/)

 * 10 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [12 years, 7 months ago](https://wordpress.org/support/topic/using-data-from-hidden-columns/#post-4299922)
 * Status: resolved