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. | NAME | GENDER | AGE | DATE | COUNTRY |
---|---|---|---|---|---|
1 | Dett2 | Female | 36 | 16/08/2020 | Great Britain |
9 | Angelee | Male | 26 | 21/05/2017 | Great Britain |
10 | Willoom | Female | 26 | 15/10/2019 | France |
8 | Dorcast | Female | 25 | 21/05/2016 | United States |
7 | Tommye | Male | 24 | 16/08/2017 | United States |
6 | Chasse | Female | 23 | 15/10/2018 | France |
5 | Shennice | Male | 22 | 21/05/2016 | France |
4 | Siuau | Female | 21 | 21/05/2015 | Great Britain |
3 | Kallsie | Male | 20 | 16/08/2016 | France |
2 | Nern | Female | 19 | 15/10/2017 | France |
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. | NAME | GENDER | AGE | DATE | COUNTRY |
---|---|---|---|---|---|
2 | Nern | Female | 19 | 15/10/2017 | France |
3 | Kallsie | Male | 20 | 16/08/2016 | France |
4 | Siuau | Female | 21 | 21/05/2015 | Great Britain |
5 | Shennice | Male | 22 | 21/05/2016 | France |
6 | Chasse | Female | 23 | 15/10/2018 | France |
7 | Tommye | Male | 24 | 16/08/2017 | United States |
8 | Dorcast | Female | 25 | 21/05/2016 | United States |
10 | Willoom | Female | 26 | 15/10/2019 | France |
9 | Angelee | Male | 26 | 21/05/2017 | Great Britain |
1 | Dett2 | Female | 36 | 16/08/2020 | Great 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. | NAME | GENDER | AGE | DATE | COUNTRY |
---|---|---|---|---|---|
2 | Nern | Female | 19 | 15/10/2017 | France |
3 | Kallsie | Male | 20 | 16/08/2016 | France |
4 | Siuau | Female | 21 | 21/05/2015 | Great Britain |
5 | Shennice | Male | 22 | 21/05/2016 | France |
6 | Chasse | Female | 23 | 15/10/2018 | France |
7 | Tommye | Male | 24 | 16/08/2017 | United States |
8 | Dorcast | Female | 25 | 21/05/2016 | United States |
10 | Willoom | Female | 26 | 15/10/2019 | France |
9 | Angelee | Male | 26 | 21/05/2017 | Great Britain |
1 | Dett2 | Female | 36 | 16/08/2020 | Great Britain |