Requirement: we want to filter out the rows which is with empty value("", or " ") when sorting, always leave the rows with empty value column to the bottom of the data table.
jQuery.fn.dataTableExt.oSort['customstring-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;
return retVal;
};
jQuery.fn.dataTableExt.oSort['customstring-desc'] = 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;
return retVal;
};
/** Initiate Data Table * */
oTable = $('#activityTable').dataTable({
"oLanguage" : {
"sSearch" : "SEARCH FLOW:"
},
bJQueryUI : true,
bLengthChange : false,
bPaginate : false,
bInfo : false,
aoColumnDefs : [ {
"sType" : "customstring",
"aTargets" : [ 1 ]
}
});
Refer to [url]https://datatables.net/examples/plug-ins/sorting_sType.html[/url]