Title: Sorting columns
Last modified: August 22, 2016

---

# Sorting columns

 *  Resolved [LizzyD](https://wordpress.org/support/users/lizzyd/)
 * (@lizzyd)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/sorting-columns/)
 * I am trying to sort on the timestamp column to put the most recent entries first.
   I am new to jquery and DataTables. I’m using a chid theme. I’ve added this to
   my functions.php:
 *     ```
       function wpb_adding_scripts() {
       wp_register_script('sort_match_log', get_template_directory_uri() . '/js/sort_match_log', array('jquery'),'1.1', true);
       wp_enqueue_script('sort_match_log');
       }
   
       add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );
       ```
   
 * And created a js file which looks like this:
 *     ```
       jQuery(window).load(function () {
           jQuery(‘#igsv-1rTt0tr5i5D8wf8eTBmqyoqzC_LrViUpt2imdqzHpCHQ/pubhtml’).dataTable().api().order([1, 'desc']).draw();
       });
       ```
   
 * The website is here:
 * [http://digitalis-darkroom.co.uk/superleague/match-log-2/](http://digitalis-darkroom.co.uk/superleague/match-log-2/)
 * Can you tell me what I’m missing?
 * [https://wordpress.org/plugins/inline-google-spreadsheet-viewer/](https://wordpress.org/plugins/inline-google-spreadsheet-viewer/)

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

 *  Plugin Author [Meitar](https://wordpress.org/support/users/meitar/)
 * (@meitar)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/sorting-columns/#post-5272969)
 * At first glance, one thing that’s certainly a mistake is including the `/pubhtml`
   in your table ID. That is, it should probably be `#igsv-1rTt0tr5i5D8wf8eTBmqyoqzC_LrViUpt2imdqzHpCHQ`.
 *  Thread Starter [LizzyD](https://wordpress.org/support/users/lizzyd/)
 * (@lizzyd)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/sorting-columns/#post-5272991)
 * OK, thanks, have fixed that. Any other suggestions?
 *  Plugin Author [Meitar](https://wordpress.org/support/users/meitar/)
 * (@meitar)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/sorting-columns/#post-5273050)
 * If the timestamp is the first column, use `.order([0, 'desc'])`, not `1`. (Column
   numbers start at `0`.) Also, I noticed that the single quotes surrounding your
   ID selector are not straightened. That is, you want to use `'`, not `‘` or `’`.
 * Finally, when I loaded your page, I got a `404 Not Found` HTTP error when loading`
   http://digitalis-darkroom.co.uk/wp-content/themes/twentytwelve/js/sort_match_log?
   ver=1.1`, so it seems wherever you placed your JavaScript file isn’t the same
   place you’re trying to retrieve it from, and thus it’s not loading at all.
 * Good luck.
 *  Thread Starter [LizzyD](https://wordpress.org/support/users/lizzyd/)
 * (@lizzyd)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/sorting-columns/#post-5273058)
 * Fantastic, thank you, got it working :0)
 *  Thread Starter [LizzyD](https://wordpress.org/support/users/lizzyd/)
 * (@lizzyd)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/sorting-columns/#post-5273164)
 * Have got this working on the live website here:
    [http://www.yorkshiredarts.org.uk/superleague/match-log/](http://www.yorkshiredarts.org.uk/superleague/match-log/)
   but it looks as if it is sorting on the day, rather than the date (first entry
   and last entry are both September, October entries are coming out in the middle).
   Can you tell me how to set this so that it knows it is a date column?
 *  Plugin Author [Meitar](https://wordpress.org/support/users/meitar/)
 * (@meitar)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/sorting-columns/#post-5273170)
 * Ummmmmm. It does seem to be sorting on the “timestamp” column? Sorry, I don’t
   think I understand your question?
 *  Plugin Author [Meitar](https://wordpress.org/support/users/meitar/)
 * (@meitar)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/sorting-columns/#post-5273171)
 * Oh, also, it occurs to me that another (and possibly easier) way to sort the 
   columns is simply to do so on the other end (i.e., from Google’s side as opposed
   to your blog’s side). You can do this on-the-fly using the `query` parameter,
   as described in the FAQ:
 * > Another option for sorting your table, for example, is to use the `query` attribute
   > and pass along an appropriate [Google Charts API Query Language query that includes an `order by` clause](https://developers.google.com/chart/interactive/docs/querylanguage#Order_By).

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

The topic ‘Sorting columns’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/inline-google-spreadsheet-viewer.
   svg)
 * [Inline Google Spreadsheet Viewer](https://wordpress.org/plugins/inline-google-spreadsheet-viewer/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/inline-google-spreadsheet-viewer/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/inline-google-spreadsheet-viewer/)
 * [Active Topics](https://wordpress.org/support/plugin/inline-google-spreadsheet-viewer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/inline-google-spreadsheet-viewer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/inline-google-spreadsheet-viewer/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [Meitar](https://wordpress.org/support/users/meitar/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/sorting-columns/#post-5273171)
 * Status: resolved