So the question has already been asked here, but the solution doesn't work for me (I might do something wrong). I want to sort my tables by alphabetical order ("type" : "natural"), but I want the empty cells to be at the bottom (for desc and asc).
I tried the previous solution given by fbas :
jQuery.fn.dataTableExt.oSort['mystring-asc'] = function(x,y) {
var retVal;
x = $.trim(x);
y = $.trim(y);
if (x==y) retVal= 0;
else if (x == "" || x == " ") retVal= 1;
else if (y == "" || y == " ") retVal= -1;
else if (x > y) retVal= 1;
else retVal = -1; // <- this was missing in version 1
return retVal;
}
jQuery.fn.dataTableExt.oSort['mystring-desc'] = function(y,x) {
var retVal;
x = $.trim(x);
y = $.trim(y);
if (x==y) retVal= 0;
else if (x == "" || x == " ") retVal= -1;
else if (y == "" || y == " ") retVal= 1;
else if (x > y) retVal= 1;
else retVal = -1; // <- this was missing in version 1
return retVal;
}
With :
$(document).ready(function() {
$('#classement').dataTable({
"aoColumns": [
null,
null,
{ "type" : "mystring" },
{ "type" : "mystring" },
null
]
} );
} );
With a table like | N° | Edit | Song | Singer | Url |
Sorting only on Song and Singer.
The emty cells are at the bottom (as expected) but now the sorting has no logic (no alphabetical order, should I use another property in dataTable?).
Does anyone have a solution?
Edit : If we add a line dynamically, how to refresh the sorting ?
$("#example").find('tbody')
.append($('<tr>')
.append($('<td>')
.text('Boro')
)
);