Skip to content

Commit

Permalink
Adds custom datatable sort so blank fields sort at bottom.
Browse files Browse the repository at this point in the history
  • Loading branch information
shelleydoljack committed Mar 1, 2018
1 parent 750de27 commit 2ada1a1
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion app/assets/javascripts/forms.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@

$(document).on('ready page:load', function () {
$('table').DataTable();
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));
}
} );
$('table').DataTable({
columnDefs: [
{type: 'non-empty-string', targets: 0} // define 'name' column as non-empty-string type
]
});
$("[data-toggle='tooltip']").tooltip();
});

0 comments on commit 2ada1a1

Please sign in to comment.