简体   繁体   中英

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?

I am working on this and to sort the table in a descending order just change the sort direction to be -1

    sortcolumn:0, // sort column 1
    sortdir:-1, // sort direction either 1 asc or -1 desc

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM