• Resolved LizzyD

    (@lizzyd)


    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/

    Can you tell me what I’m missing?

    https://ww.wp.xz.cn/plugins/inline-google-spreadsheet-viewer/

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

    (@meitar)

    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

    (@lizzyd)

    OK, thanks, have fixed that. Any other suggestions?

    Plugin Author Meitar

    (@meitar)

    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

    (@lizzyd)

    Fantastic, thank you, got it working :0)

    Thread Starter LizzyD

    (@lizzyd)

    Have got this working on the live website here:
    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

    (@meitar)

    Ummmmmm. It does seem to be sorting on the “timestamp” column? Sorry, I don’t think I understand your question?

    Plugin Author Meitar

    (@meitar)

    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.

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

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