Conditional Sorting?
Conditional Sorting?
I would like to know if it is possible to have a conditional sorting for a few of my tables?
I have a Standings page for a hockey league and the code below shows the sorting as it currently is. Right now it is just sorting by points.
$(document).ready(function() {
$('#standTable').DataTable( {
"order": [[ 4, "desc" ]],
"sDom": 'rt',
} );
} );
The client wants to have it so that there is a tie breaking system for 1st place. I have a 5th column, and if he needs a tie breaker he just inserts numbers as he wants the ranking to be.
What I would like to know is if I can have the table switch sorting from column 4 to 5 IF column 5 is NOT NULL?
Something like(obviously this is wrong...I just need some guidance on how to approach this..):
$(document).ready(function() {
$('#standTable').DataTable( {
if( column5 == "" ){
"order": [[ 4, "desc" ]],
"sDom": 'rt',
}else{
"order": [[ 5, "desc" ]],
"sDom": 'rt'
}
} );
} );
I hope this makes sense...Thanks in advance for any help.
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
Answers
Use
columns.orderData
. For example:orderData: [ 4, 5 ]
in this case. That says that if the data being compared in column index 4 is identical, then use the data from column index 5.Allan