Sort by two columns in an inverse direction, when a column's sort button is clicked

Sort by two columns in an inverse direction, when a column's sort button is clicked

serverFaultserverFault Posts: 9Questions: 4Answers: 0

Hello All.

In our table we have a column that displays a graphical icon that is color-coded to indicate severity, like a flag. Right now clicking the sort icon for that column uses a hidden value in that column (a span element that is not visible), however going forward we want to change that so that it first sorts it by that column, and then by a second column also not visible.

I know how to achieve multi-column sorting as a default, or attached to a click handler, but I'm not sure how to accomplish this so that it's the method used when a user click the built-in sorting icon for that column.

Using columnDefs I know how to specify multi-column ordering to a target, but I don't know how to assign a direction.

For example, when target 1 is clicked, I want the table to sort by 1 desc, and 2 asc. If clicked a second time both would reverse, so 1-asc 2-desc. How would I do this? Is this possible?

Something like below, but where the order for 2 is the inverse of 1.

'columnDefs': [
    { 'orderData':[1,2], 'targets': [1] },
     ]

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    No, sorry. At this time that is not possible. The will both sort in the same direction.

    If you need more control, what you could do is remove the default DataTables listener for the click event on the header and instead add your own which would call order() with the combined ordering as needed.

    Allan

Sign In or Register to comment.