formatted-numbers.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * This plug-in will provide numeric sorting for numeric columns which have
  3. * extra formatting, such as thousands separators, currency symbols or any other
  4. * non-numeric data.
  5. *
  6. * By default when a cell is found to have no numeric data its value is sorted
  7. * numerically as if its value were 0. This could also be altered to be Inifnity
  8. * or -Infinity as required.
  9. *
  10. * DataTables 1.10+ has formatted number detection and sorting abilities built-
  11. * in. As such this plug-in is marked as deprecated, but might be useful when
  12. * working with old versions of DataTables.
  13. *
  14. * @name Formatted numbers
  15. * @summary Sort numbers which are displayed with thousand separators
  16. * @deprecated
  17. * @author [Allan Jardine](http://sprymedia.co.uk)
  18. *
  19. * @example
  20. * $('#example').dataTable( {
  21. * columnDefs: [
  22. * { type: 'formatted-num', targets: 0 }
  23. * ]
  24. * } );
  25. */
  26. jQuery.extend( jQuery.fn.dataTableExt.oSort, {
  27. "formatted-num-pre": function ( a ) {
  28. a = (a === "-" || a === "") ? 0 : a.replace( /[^\d\-\.]/g, "" );
  29. return parseFloat( a );
  30. },
  31. "formatted-num-asc": function ( a, b ) {
  32. return a - b;
  33. },
  34. "formatted-num-desc": function ( a, b ) {
  35. return b - a;
  36. }
  37. } );