Support » Plugin: WP-Table Reloaded » column type

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

    (@tobiasbg)

    Hi,

    thanks for your question.

    Manually assigning column types should not really be necessary, as the DataTables JavaScript library, which brings the sorting functionality when the table is viewed by a visitor, usually detects the type automatically. I’m pretty sure that there is a sorting type for dates, but I’m not really sure about times. Just setting the type manually (which is possible with some code) would not be enough anyway: You would also have to develop and add a custom sorting algorithm for times then.

    Can you maybe post the link to the page with your table? I can then try to suggest what to do.

    Regards,
    Tobias

    Hi. Thanks for your followup. The link to my table is: http://jcjunkie.com/audio/

    You can see that the ‘length’ column (minutes) is not sorting correctly. Also, how do I set the default sort to be column 4 (date) not column 1 (title). I’d like the table to be sorted by date not title. Thanks.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for this extra information.

    The “Lenght” does not sort correctly, because technically this column contains “strings”, and not number (due to the ” min” part added). If you want these sorted correctly, you will need to developer a custom sorting algorithm with the help of the DataTables documentation at http://www.datatables.net/ , or drop the ” min” part and maybe put that into the column head cell of that column.
    For the dates: These should sort correct, if you use “mm/dd/yy” as the date format. Otherwise, you will also need a different sorting algorithm.

    Regards,
    Tobias

    i’ll try that with the numbers. I was wondering if you could address the second part of my question namely how do set the table to default sort on a column other than column 1. Thank you!

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    argh, I totally forgot about that question. Sorry about that!

    To change the default sorting column, just add the following code into the “Custom Commands” textfield in the “DataTables JavaScript Features” section on the table’s “Edit” screen:

    "aaSorting": [[3, 'asc' ]]

    This will perform an initial sort on column 4 (as counting in the code starts with 0).

    Regards,
    Tobias

    aa lol, yesterday i made a code to do that in dashboard lol, but in fact i could simply like that 🙁 cf : Post support

    so just in case if someone want the code to do a default sort directly in dashboard with shortcode :

    add_filter( 'wp_table_reloaded_post_load_table', 'wp_table_reloaded_execute_shortcode_before_sort',10,2 );
    add_filter( 'wp_table_reloaded_filter_sort_pre', 'wp_table_reloaded_execute_filter_sort_pre' );
    add_filter( 'wp_table_reloaded_pre_save_table', 'wp_table_reloaded_before_save_sort',10,1 );
    
    function wp_table_reloaded_before_save_sort( $table ) {
    	if(isset($table['data']) && isset($table['data_hash'])) {
    		foreach($table['data'] as $k => $v) {
    			$save_v = $v;
    			unset($v[5]);
    			$hash = md5(implode('-',$v));
    			$table['data'][$k][5] = $table['data_hash'][$hash];
    		}
    	}
    
    	return $table;
    }
    
    function wp_table_reloaded_execute_filter_sort_pre( $value ) {
    	return do_shortcode($value);
    }
    
    function wp_table_reloaded_execute_shortcode_before_sort($table,$table_id) {
    	if(isset($_POST['submit']['sort'])) {
    		if(isset($table['data'])){
    			$table['data_hash'] = array();
    			foreach($table['data'] as $k => $v) {
    				$vv = $v;
    				unset($vv[5]);
    				$table['data_hash'][md5(implode('-',$vv))] = $v[5];
    				$v[5] = apply_filters( 'wp_table_reloaded_filter_sort_pre', $v[5] );
    				$table['data'][$k] = $v;
    			}
    		}
    	}
    
    	return $table;
    }

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    cool! Thanks for sharing your code! If someone wants to do that, they now have the chance 🙂

    @jeronimo42: Don’t get confused, you will only need the small code from my last post.

    Best wishes,
    Tobias

    Thank you so much for your help. My table is sorting the way I want it now. Thank you for your quick replies.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    sure, no problem! 🙂
    You are very welcome!

    Best wishes,
    Tobias

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘column type’ is closed to new replies.