Jenny
Jenny

Reputation: 919

Sort table on page load

My goal is to have my table display on page load in descending order by donation total. I am using table sorter to sort the table. The website is created using software, I cannot directly edit the HTML.

Currently, if I click on the donation total it will sort descending but I do not want viewers to have to click. If possible I would like the page to display in descending order by default and not have the option to click to sort ascending.

Please see http://jsfiddle.net/jelane20/kt8jzg9e/3/ for the current HTML

Here is the script that is currently in place:

$("document").ready(function() {

var $existTable= $('table td table');

var $newTable = $('<table id="newTable"><thead></thead><tbody></tbody></table>');
$newTable.find('thead').append($existTable.find('tr').eq(2));
$newTable.find('tbody').append($existTable.find('tr:gt(1)'));
$existTable.parent().append( $newTable );


$newTable.tablesorter({

// default sortInitialOrder setting 
sortInitialOrder: "asc", 

// pass the headers argument and passing a object 
headers: {

    3: { sortInitialOrder: 'desc' }

 }

    });
});

Thank you so much!

Upvotes: 3

Views: 1722

Answers (1)

gere
gere

Reputation: 1730

To sort on the fourth column, descending, initially, you should use:

sortList: [[3,1]]

And to disable the sorting on click on the fourth column:

 headers: {
        3: {sorter: false } 
    }

Here is a working copy of your code: http://jsfiddle.net/tkcrpep5/

Upvotes: 2

Related Questions