Title: column type
Last modified: August 20, 2016

---

# column type

 *  Resolved [jeronimo42](https://wordpress.org/support/users/jeronimo42/)
 * (@jeronimo42)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/column-type/)
 * Is there a way to assign data typing to my table, for example DATE and TIME categories?
   I want a column for date and a column for time and to be able to sort my table
   based on those categories. Is this possible? Thank you!
 * [http://wordpress.org/extend/plugins/wp-table-reloaded/](http://wordpress.org/extend/plugins/wp-table-reloaded/)

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

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/column-type/#post-3209726)
 * 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
 *  Thread Starter [jeronimo42](https://wordpress.org/support/users/jeronimo42/)
 * (@jeronimo42)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/column-type/#post-3209759)
 * Hi. Thanks for your followup. The link to my table is: [http://jcjunkie.com/audio/](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 [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/column-type/#post-3209761)
 * 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/](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
 *  Thread Starter [jeronimo42](https://wordpress.org/support/users/jeronimo42/)
 * (@jeronimo42)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/column-type/#post-3209767)
 * 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 [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/column-type/#post-3209770)
 * 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
 *  [Radyium](https://wordpress.org/support/users/radyium/)
 * (@radyium)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/column-type/#post-3209774)
 * aa lol, yesterday i made a code to do that in dashboard lol, but in fact i could
   simply like that 🙁 cf :[ Post support ](http://wordpress.org/support/topic/pre-action-before-sort-on-edit-dashboard?replies=5)
 * 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 [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/column-type/#post-3209775)
 * Hi,
 * cool! Thanks for sharing your code! If someone wants to do that, they now have
   the chance 🙂
 * [@jeronimo42](https://wordpress.org/support/users/jeronimo42/): Don’t get confused,
   you will only need the small code from my last post.
 * Best wishes,
    Tobias
 *  Thread Starter [jeronimo42](https://wordpress.org/support/users/jeronimo42/)
 * (@jeronimo42)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/column-type/#post-3209783)
 * 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 [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/column-type/#post-3209784)
 * 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.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-table-reloaded_f7dcd3.svg)
 * [WP-Table Reloaded](https://wordpress.org/plugins/wp-table-reloaded/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-table-reloaded/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-table-reloaded/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-table-reloaded/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-table-reloaded/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-table-reloaded/reviews/)

 * 9 replies
 * 3 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/column-type/#post-3209784)
 * Status: resolved