How to sort 2 by 2 different Data Points in the same column by choice

How to sort 2 by 2 different Data Points in the same column by choice

Venky1995Venky1995 Posts: 14Questions: 9Answers: 0

Hi everybody,
I am working with data Tables for a major project. All my data is JSON type. I was successfully able to get the Scientific and Common names of species in the same column using the columnDefs API reference. But in my case I wanted to give the user a choice to sort by Scientific Name or by Common Name. Since they both exist in the same Column, my current set up only lets me sort by Scientific Name alone. I want the user to see Two Sort Arrows as well as 2 column headers "Sci. Name" and "Com. Name" such that they have access to any type of sorted list at any point.Any help will be appreciated.

Here is a code Snippet of how the columns are rendered.

"columnDefs": [
{
"title": "Scientific Name <br> <br> <br><th>Common Name</th>",
"render": function (data, type, row) {
return row[0] + '<br><br>

' + row[1] + '

';
},
"targets": 0
},
{ "visible": false, "targets": [1] }
],

PS: DataTables are the best! Thanks for making life easier!

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @Venky1995 ,

    My final post in this thread should do the trick - it's doing something similar.

    Cheers,

    Colin

This discussion has been closed.