So the question is, how to sort a datatable and ignoring the empty cells (or cells with just "-"). More accurate I want the empty cells to be at the bottom (for desc and asc). This Question has already been answered here Sorting (alphabetical order) to ignore empty cells : dataTables. But the solution doesn't work for me, because i have a Client-side data source and the new sorting takes forever.
Update:
By adding this code, if you click on the first entry (ID), the whole sorting takes far too long.
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"non-empty-string-asc": function (str1, str2) {
if(str1 == "")
return 1;
if(str2 == "")
return -1;
return ((str1 < str2) ? -1 : ((str1 > str2) ? 1 : 0));
},
"non-empty-string-desc": function (str1, str2) {
if(str1 == "")
return 1;
if(str2 == "")
return -1;
return ((str1 < str2) ? 1 : ((str1 > str2) ? -1 : 0));
}
} );
var dataTable = $('#example').dataTable({
columnDefs: [
{type: 'non-empty-string', targets: 0} // define 'name' column as non-empty-string type
]
});`
Example: https://jsfiddle.net/36zxs9f6/2/