• Resolved r.clark15

    (@rclark15)


    I have installed the DataTables Inverted Filter plugin. I’ve read all of the threads that pertain to this plugin. I don’t know what I need to enter into line 22 for [table id=4 /] with a URL slug of data-test to not show table data until searched.

    <?php
    /*
    Plugin Name: TablePress Extension: DataTables Inverted Filter
    Plugin URI: https://tablepress.org/extensions/datatables-inverted-filter/
    Description: Custom Extension for TablePress to hide all rows initially (i.e. when the DataTables filter word is empty)
    Version: 1.1
    Author: Tobias B?thge
    Author URI: https://tobias.baethge.com/
    */

    /*
    * See https://datatables.net/forums/discussion/14521/have-filter-return-no-rows-when-filter-string-is-empty#Item_1
    *
    * Adjust page slugs as necessary in the array below.
    */

    /*
    * Register necessary Plugin Filters.
    */
    add_filter( ‘tablepress_all_datatables_commands’, ‘tablepress_datatables_inverted_filter’ );

    /**
    * Add DataTables Inverted Filter JS code.
    *
    * @since 1.0
    *
    * @param array $commands The JS commands for the DataTables JS library.
    * @return array Modified JS commands for the DataTables JS library.
    */
    function tablepress_datatables_inverted_filter( $commands ) {
    // Only use this functionality on these pages:
    if ( ! is_page( array( ‘page-slug-1’, ‘page-slug-1’ ) ) ) {
    return $commands;
    }

    $commands = <<<JS
    $.fn.dataTableExt.afnFiltering.push(
    function( settings, data, dataIndex ) {
    return ” !== settings.oPreviousSearch.sSearch;
    }
    );
    {$commands}
    $( ‘.dataTables_filter’ ).find( ‘input’ ).on( ‘keyup’, function() {
    $( ‘.dataTables_wrapper’ ).find( ‘.tablepress’ ).toggle( ” !== $( this ).val() );
    } ).keyup();
    JS;

    return $commands;
    }

    The page I need help with: [log in to see the link]

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

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.
    Also sorry for the late reply! As I was on holidays, I did not have a chance to look at this earlier.

    That line should become

    if ( ! is_page( array( 'data-test' ) ) ) {
    

    Also, don’t forget to install and activate this TablePress Extension as a plugin on your site.

    Regards,
    Tobias

    Thread Starter r.clark15

    (@rclark15)

    Hello Sir,
    This was what I should add to line 22;if ( ! is_page( array( ‘data-test’ ) ) ) {

    This is what you emailed me; if ( ! is_page( array( 'data-test' ) ) ) {

    Sadly neither one of these options. Please advise.

    Cheers,
    Rich

    Thread Starter r.clark15

    (@rclark15)

    Hello Sir,
    This was what I should add to line 22;if ( ! is_page( array( ‘data-test’ ) ) ) {

    This is what you emailed me; if ( ! is_page( array( 'data-test' ) ) ) {

    Sadly neither one of these options. Sorry for having to send twice. Please advise.

    Cheers,
    Rich

    • This reply was modified 5 years, 4 months ago by r.clark15.
    Plugin Author TobiasBg

    (@tobiasbg)

    Hi Rich,

    the solution from these forums (and not that from an automatic notification email) is always better:

    if ( ! is_page( array( 'data-test' ) ) ) {
    

    Please make sure that the TablePress Extension is installed and activated as well!

    Regards,
    Tobias

    Thread Starter r.clark15

    (@rclark15)

    Got it! Thanks

    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 6 replies - 1 through 6 (of 6 total)
  • The topic ‘DataTables Inverted Filter’ is closed to new replies.