Advertisement
austinh115

[JS/jQuery] Table sorting on formatted numbers (FEX)

Aug 12th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.82 KB | None | 0 0
  1.         jQuery.fn.dataTableExt.oSort['num-html-asc'] = function(a,b) {
  2.             var x = a.replace(/[^0-9]/g, "");
  3.             var y = b.replace(/[^0-9]/g, "");
  4.             x = parseFloat( x );
  5.             y = parseFloat( y );
  6.             return ((x < y || isNaN(y) ) ? -1 : ((x > y || isNaN(x)) ? 1 : 0));
  7.         };
  8.  
  9.         jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
  10.             var x = a.replace(/[^0-9]/g, "");
  11.             var y = b.replace(/[^0-9]/g, "");
  12.             x = parseFloat( x );
  13.             y = parseFloat( y );
  14.             return ((x < y || isNaN(x)) ? 1 : ((x > y || isNaN(y) ) ? -1 : 0));
  15.         }; 
  16. //^ put those after the function dtShowHideCol( iCol )
  17.  
  18.  
  19.  
  20. //put this inside the $(document).ready(function()
  21. //before $('.datatable-controls').on(...)
  22. x = $("#caughtList").dataTable();
  23.     x.fnSettings().aoColumns[6].sType = "num-html";
  24.     x.fnSettings().aoColumns[5].sType = "num-html";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement