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

    (@tobiasbg)

    Hi,

    thanks for your question.

    For this, you have three possibilities:
    The easiest would be to simply sort the table on the “Edit” screen and then save it. Just click the sorting arrow near that column name (B) to do that.
    Another idea would be to use a “Custom Command” for the DataTables JS library. That would sort the table directly after loading, in the same way as if the user had clicked on column B, but without needing the actual click. To do that, just add

    "aaSorting": [[1,'desc']]

    to the “Custom Commands” textfield on the “Edit” screen of the table.
    And the third option would be to use the Table Row Order Extension from http://tablepress.org/extensions/table-row-order/ that allows this with an extra Shortcode parameter.

    Regards,
    Tobias

    Thread Starter kingman33

    (@kingman33)

    Worked perfectly thanks.

    Have another question if you don’t mind! So with the OLD plugin (tables reloaded), you helped resolve this: http://wordpress.org/support/topic/plugin-wp-table-reloaded-url-to-link-conversion-with-nametitle?replies=16

    How can I do this with TablePress ? (automatically make it so a URL in a cell outputs as a clickable link “More Info”)

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    great to hear that this worked! 🙂

    For the link issue:
    That can be done in exactly the same way, you’ll just have to replace all occurances of “wp_table_reloaded” with “tablepress”, i.e. the first two lines of the code need to become

    add_filter( 'tablepress_cell_content', 'tablepress_add_custom_links', 10, 4 );
    function tablepress_add_custom_links( $cell_content, $table_id, $row_idx, $col_idx ) {

    Regards,
    Tobias

    Thread Starter kingman33

    (@kingman33)

    awesome, and if I want to do it for another table too (so table #1 and #2) …. do I have to repeat that whole thing ? I tried doing that but got a “syntax error” on the page. See below. Thanks

    <?php
    /*
    Plugin Name: WP-Table Reloaded Extensions
    Plugin URI: http://tobias.baethge.com/wordpress-plugins/wp-table-reloaded-english/extensions/
    Description: Custom Extensions for WP-Table Reloaded
    Version: 1.0
    Author: YOU, Tobias Baethge
    */
    
    // this is where the actual code goes
    
    add_filter( 'tablepress_cell_content', 'tablepress_add_custom_links', 10, 4 );
    function tablepress_add_custom_links( $cell_content, $table_id, $row_idx, $col_idx ) {
    	if ( 1 != $table_id )
    		return $cell_content;
    
    	if ( 6 != $col_idx )
    		return $cell_content;
    
    	if ( 1 == $row_idx )
    		return $cell_content;
    
    	return '<a href="' . $cell_content . '"><b><font color="#0000FF"><u>Click for More Info</u></b></a></font color>';
    
    add_filter( 'tablepress_cell_content', 'tablepress_add_custom_links', 10, 4 );
    function tablepress_add_custom_links( $cell_content, $table_id, $row_idx, $col_idx ) {
    	if ( 2 != $table_id )
    		return $cell_content;
    
    	if ( 5 != $col_idx )
    		return $cell_content;
    
    	if ( 1 == $row_idx )
    		return $cell_content;
    
    	return '<a href="' . $cell_content . '"><b><font color="#0000FF"><u>Click for More Info</u></b></a></font color>';
    
    }
    ?>
    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no repeating this will not work. Instead, you’ll have to edit the code a little bit. Please try again with:

    add_filter( 'tablepress_cell_content', 'tablepress_add_custom_links', 10, 4 );
    function tablepress_add_custom_links( $cell_content, $table_id, $row_idx, $col_idx ) {
    	if ( ! in_array( $table_id, array( '123', '456' ) ) )
    		return $cell_content;
    
    	if ( 0 !== stripos( $cell_content, 'http' ) )
    		return $cell_content;
    
    	return '<a href="' . $cell_content . '"><b><font color="#0000FF"><u>Click for More Info</u></b></a></font>';
    }

    The array( '123', '456' ) is a comma-separated list of all tables where you want this happen.
    Also note that I made the code more flexible, so that you won’t need to mess with row and column numbers. Instead, the code now simply checks the cell content for a URL and then converts that.

    Regards,
    Tobias

    Thread Starter kingman33

    (@kingman33)

    woooo, that worked. Almost there, one more thing. I tried getting the links to open in a new window, and changed the last few lines of code to the following: (target=”_blank”)

    return '<a href="' . $cell_content . '" target="_blank"><b><font color="#0000FF"><u>Click for More Info</u></b></a></font>';
    }
    ?>

    But the links are still opening in the same window and not in a new window. Any idea?

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    that looks perfectly correct.

    It might be possible that the old version is still in the cache, so just re-save the table again. If it still dos not work, please post a link to the page with the table. Thanks!

    Regards,
    Tobias

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Auto-sort a column from highest to lowest without having to click arrow’ is closed to new replies.