Pinkie Pinkie - 1 month ago 6
Javascript Question

tinytable how to sort table in descending order rather then ascending

I'm using the tinytable table sorting script.

See example at http://sandbox.scriptiny.com/table-sorter/index.html.

It's a very basic script about 2.5kb. To use the script we do

sorter.init("table",1);
where table is the table id and 1 is the initial column to be sorted. This works great but initial column is sorted in asc order. There is not an option to make it initially sort in descending order. I tried to look into the js file but couldn't figure it out. What do I need to do to make it the initial column sort in desc order?

Answer

One line of the script reads return g>h?1:(g<h?-1:0).

Change it to return g<h?1:(g>h?-1:0) and you should be done.

Edit:

If you click on the Name cell of the intial column, it also sort in descending order.