CSV to html – sorting data

Sorting data

Use sort_cols together with sort_cols_order: This sorting mechanism sorts firstly on the given column, and then next given column and then next column specified etc. (It’s not a sorting that sorts either column 4 or 1. It takes all columns specified as sorting in consideration). In this case column 4 are sorted descending (age), and then column 1 as sorted ascending. (Age 26 exists twice and SR. are sorted ascending (9 and 10).

Shortcode
[csvtohtml_create source_type="guess" source_files="*free_testdata_10rows.csv" sort_cols="4,1" sort_cols_order="desc,asc"]
SR.NAMEGENDERAGEDATE COUNTRY
1Dett2Female3616/08/2020Great Britain
9AngeleeMale2621/05/2017Great Britain
10WilloomFemale2615/10/2019France
8DorcastFemale2521/05/2016United States
7TommyeMale2416/08/2017United States
6ChasseFemale2315/10/2018France
5ShenniceMale2221/05/2016France
4SiuauFemale2121/05/2015Great Britain
3KallsieMale2016/08/2016France
2Nern Female1915/10/2017France

The second option is to use a plugin called Table Sorter and then apply correct class (tablesorter) for the table so it will work. The code below sets a specific sortorder at start and then the Table Sort plugin makes it possible for the user to click on different columns to sort them.

Shortcode
[csvtohtml_create html_class="tablesorter" source_type="guess" source_files="*free_testdata_10rows.csv" sort_cols="4,1" sort_cols_order="asc,desc"]
SR.NAMEGENDERAGEDATE COUNTRY
2Nern Female1915/10/2017France
3KallsieMale2016/08/2016France
4SiuauFemale2121/05/2015Great Britain
5ShenniceMale2221/05/2016France
6ChasseFemale2315/10/2018France
7TommyeMale2416/08/2017United States
8DorcastFemale2521/05/2016United States
10WilloomFemale2615/10/2019France
9AngeleeMale2621/05/2017Great Britain
1Dett2Female3616/08/2020Great Britain

From version 1.7.5 it’s all builtin into the plugin. Simply add sort_cols_userclick=”yes” to your shortcode!

Shortcode
[csvtohtml_create source_type="guess" source_files="*free_testdata_10rows.csv" sort_cols="4,1" sort_cols_order="asc,desc" sort_cols_userclick="yes"]
SR.NAMEGENDERAGEDATE COUNTRY
2Nern Female1915/10/2017France
3KallsieMale2016/08/2016France
4SiuauFemale2121/05/2015Great Britain
5ShenniceMale2221/05/2016France
6ChasseFemale2315/10/2018France
7TommyeMale2416/08/2017United States
8DorcastFemale2521/05/2016United States
10WilloomFemale2615/10/2019France
9AngeleeMale2621/05/2017Great Britain
1Dett2Female3616/08/2020Great Britain