• Resolved usajko

    (@usajko)


    hi!

    When I added hide_columns parameter in shortcode, datatables_counter_column stop working and the table is not sortable anymore no metter if I add datatables_sort=true

    My shortcode:
    [table id=2 datatables_counter_column=true hide_rows=”2″ hide_columns=”4-11″]

    Thank you for your help.

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

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for your question, and sorry for the trouble.

    This is because of the “Custom Command”

    { "type": "date", "targets": [ 3 ] }, { "type": "number", "targets": [ 4, 5 ] }
    

    This would refer to columns that no longer exist and causes an error. You should remove this part of the code as well if you hide the columns.

    Regards,
    Tobias

    Thread Starter usajko

    (@usajko)

    I forgot to tell you … in crovser console is an error:

    Uncaught TypeError: Cannot set property ‘_DT_CellIndex’ of undefined
    at Ha (jquery.datatables.min.js?ver=1.9.2:24)
    at O (jquery.datatables.min.js?ver=1.9.2:16)
    at HTMLTableRowElement.<anonymous> (jquery.datatables.min.js?ver=1.9.2:17)
    at jquery.js?ver=1.12.4-wp:2
    at Function.map (jquery.js?ver=1.12.4-wp:2)
    at a.fn.init.map (jquery.js?ver=1.12.4-wp:2)
    at na (jquery.datatables.min.js?ver=1.9.2:16)
    at e (jquery.datatables.min.js?ver=1.9.2:92)
    at HTMLTableElement.<anonymous> (jquery.datatables.min.js?ver=1.9.2:93)
    at Function.each (jquery.js?ver=1.12.4-wp:2)
    Ha @ jquery.datatables.min.js?ver=1.9.2:24
    O @ jquery.datatables.min.js?ver=1.9.2:16
    (anonymous) @ jquery.datatables.min.js?ver=1.9.2:17
    (anonymous) @ jquery.js?ver=1.12.4-wp:2
    map @ jquery.js?ver=1.12.4-wp:2
    map @ jquery.js?ver=1.12.4-wp:2
    na @ jquery.datatables.min.js?ver=1.9.2:16
    e @ jquery.datatables.min.js?ver=1.9.2:92
    (anonymous) @ jquery.datatables.min.js?ver=1.9.2:93
    each @ jquery.js?ver=1.12.4-wp:2
    each @ jquery.js?ver=1.12.4-wp:2
    n @ jquery.datatables.min.js?ver=1.9.2:83
    h.fn.DataTable @ jquery.datatables.min.js?ver=1.9.2:165
    (anonymous) @ (index):879
    i @ jquery.js?ver=1.12.4-wp:2
    fireWith @ jquery.js?ver=1.12.4-wp:2
    ready @ jquery.js?ver=1.12.4-wp:2
    J @ jquery.js?ver=1.12.4-wp:2

    Thread Starter usajko

    (@usajko)

    Hi

    Thank you for your replay. I possible to add Custom Command dynamically via shortcode?
    I’m using same table on more pages and I should define data types for columns.

    Best regards,
    Uros

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    setting these via the Shortcode parameter is a bit tricky, as it can potentially be a security risk. Therefore, you’ll first have to activate this, by adding the code

    add_filter( 'tablepress_disable_custom_commands_shortcode_parameter', '__return_false' );
    

    to your theme’s functions.php file.

    After that, you can try to set “Custom Commands” in the Shortcode, but will have to use single quotes, like

    [table id=123 datatables_custom_commands="'columnDefs': [ { 'type': 'accents', 'targets': [ 1, 2 ] } ]" /]
    

    Now, I’m not exactly sure (haven’t tested this for a while), but it might be possible that this will not work, due to the ] in the parameter value…

    Regards,
    Tobias

    Thread Starter usajko

    (@usajko)

    Hi!

    You are right, it’s not working due to the ]

    Best regards,
    Uros

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    sorry about that then. Unfortunately, I don’t see other ways here then ??

    Regards,
    Tobias

    Thread Starter usajko

    (@usajko)

    hi!

    Is there any option that I add my own shortcode into functions.php, that has same parameters as existing tablepress shortcode and in this mz function adds custom command string directly into $shortcode_atts array and then call your shortcode_table function (not sure if this functon is right one and how to call):

    Something like this but I don’t know how and which function to call:

    add_shortcode('customordertable', 'customorder_table');
    function customorder_table( $params = array() ) {
        $pramas['datatables_custom_commands']="'columnDefs': [ { 'type': 'accents', 'targets': [ 1, 2 ] } ]";
        shortcode_table ($params); //this is call of your existin function 
    }

    Best regards,
    Uros

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    yes, that could actually work.

    You would then use

    return tablepress_get_table( $params );
    

    in your custom function.

    Regards,
    Tobias

    Thread Starter usajko

    (@usajko)

    hi!

    When I added the code in functions.php, my admin pages mot working:

    add_filter( 'tablepress_disable_custom_commands_shortcode_parameter', '__return_false' );
    add_shortcode('customordertable', 'customorder_table');
    function customorder_table( $params ) {
        $pramas['datatables_custom_commands']="'order': [[ 1, 'asc' ]]";
        return tablepress_get_table( $params );
    }

    I got an error: The site is experiencing technical difficulties.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    it looks like there is a typo:
    $pramas instead of $params

    For additional information, I recommend to check the server error log file.

    Regards,
    Tobias

    Thread Starter usajko

    (@usajko)

    Hi!

    Yes, it is typo – thank you! But this is not a reason that I get error message: The site is experiencing technical difficulties. Please check your site admin email inbox for instructions.

    There is no error in server error log file.
    The page with my new shortcode “customordertable” is working, also sorting via $pramas['datatables_custom_commands'] is working, but when I want to edit the page where is located shortcode “customordertable” is not working. Only that page cannot be open for edit.

    When I comment out the line return tablepress_get_table( $params ); I can edit page again.

    It is very strange. Do you have maybe any slolution?

    Have a nice day,
    Uros

    Thread Starter usajko

    (@usajko)

    Hi!

    I think, I found working solution:

    add_shortcode('customordertable', 'customorder_table');
    function customorder_table( $params ) {
        if(! is_admin()) {
            add_filter( 'tablepress_disable_custom_commands_shortcode_parameter', '__return_false' );
            $params['datatables_custom_commands']="'order': [[ 1, 'asc' ]]";
            return tablepress_get_table( $params );
        } else {
            return;
        }
    }

    Thank you very much for your help!

    Regards,
    Uros

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    can you please try replacing

    add_shortcode('customordertable', 'customorder_table');
    

    with

    if ( function_exists( 'tablepress_get_table' ) ) {
      add_shortcode('customordertable', 'customorder_table');
    }

    Regards,
    Tobias

    Thread Starter usajko

    (@usajko)

    Hi Tobias,

    I found out that my solution is not working in all cases. If I’m logged out to my web site I get web page but there is no table, only shortcode.

    I also test your recommended change, but it is even worst. It look that function_exists( 'tablepress_get_table' ) is FALSE and now I always see my shortcut instead of the table, regardless I’m logged in to my web site or not.

    Regards,
    Uros

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    my bad. Yes, the is_admin() check from the other piece of code should be better. Does that work?

    Regards,
    Tobias

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘hide_columns disable counter and tabel is not sortable anymore’ is closed to new replies.